29 using System.Collections;
30 using System.Collections.Generic;
33 using System.Reflection;
35 using System.Text.RegularExpressions;
40 namespace OpenSim.Framework.Servers.HttpServer
46 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62 Dictionary<string, Regex> query,
63 Dictionary<string, Regex> headers, Regex whitelist)
64 : base(method, path, query, headers, new Regex(
@"^text/html", RegexOptions.IgnoreCase | RegexOptions.Compiled),
75 : this(handler, new Regex(
@"^GET$", RegexOptions.IgnoreCase | RegexOptions.Compiled), null, null, null, null)
85 Hashtable responseData = _handler(request.
Query);
87 int responseCode = (int)responseData[
"int_response_code"];
88 string responseString = (string)responseData[
"str_response_string"];
89 string contentType = (string)responseData[
"content_type"];
94 if (
string.IsNullOrEmpty(contentType))
96 contentType =
"text/html";
106 if (responseCode == (
int)OSHttpStatusCode.RedirectMovedPermanently)
108 response.RedirectLocation = (string)responseData[
"str_redirect_location"];
109 response.StatusCode = responseCode;
112 response.AddHeader(
"Content-type", contentType);
116 if (!contentType.Contains(
"image"))
118 buffer = Encoding.UTF8.GetBytes(responseString);
122 buffer = Convert.FromBase64String(responseString);
125 response.SendChunked =
false;
126 response.ContentLength64 = buffer.Length;
127 response.ContentEncoding = Encoding.UTF8;
131 response.Body.Write(buffer, 0, buffer.Length);
135 _log.ErrorFormat(
"[OSHttpHttpHandler]: Error: {0}", ex.Message);
142 return OSHttpHandlerResult.Done;
OSHttpResponse is the OpenSim representation of an HTTP response.
OSHttpHttpHandler(GenericHTTPMethod handler, Regex method, Regex path, Dictionary< string, Regex > query, Dictionary< string, Regex > headers, Regex whitelist)
Instantiate an HTTP handler.
delegate XmlRpcResponse OSHttpHttpProcessor(XmlRpcRequest request)
override OSHttpHandlerResult Process(OSHttpRequest request)
Invoked by OSHttpRequestPump.
delegate Hashtable GenericHTTPMethod(Hashtable request)
OSHttpHttpHandler(GenericHTTPMethod handler)
Instantiate an HTTP handler.
OSHttpStatusCode
HTTP status codes (almost) as defined by W3C in http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html and IETF in http://tools.ietf.org/html/rfc6585