public DecoderProviderTest() { _myDecoder = new MyDefaultDecoder(); _provider = new FormDecoderProvider(); _provider.Add(_myDecoder); _provider.Add(new XmlDecoder()); _stream = new MemoryStream(); StreamWriter writer = new StreamWriter(_stream); writer.WriteLine("<user><firstname>jonas</firstname></user>"); writer.Flush(); _stream.Seek(0, SeekOrigin.Begin); }
/// <summary> /// Decode body into a form. /// </summary> /// <param name="providers">A list with form decoders.</param> /// <exception cref="InvalidDataException">If body contents is not valid for the chosen decoder.</exception> /// <exception cref="InvalidOperationException">If body is still being transferred.</exception> public void DecodeBody(FormDecoderProvider providers) { if (_bodyBytesLeft > 0) throw new InvalidOperationException("Body have not yet been completed."); _form = providers.Decode(_headers["content-type"], _body, Encoding.UTF8); if (_form != HttpInput.Empty) _param.SetForm(_form); }
public void DecodeBody(FormDecoderProvider providers) {}
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param> /// <param name="sessionStore">A session store is used to save and retrieve sessions</param> /// <param name="logWriter">The log writer.</param> /// <seealso cref="IFormDecoder"/> /// <seealso cref="FormDecoderProviders"/> /// <seealso cref="LogWriter"/> /// <seealso cref="IHttpSessionStore"/> public HttpServer(FormDecoderProvider decoderProvider, IHttpSessionStore sessionStore, ILogWriter logWriter) { Check.Require(decoderProvider, "decoderProvider"); Check.Require(sessionStore, "sessionStore"); _components = new ComponentProvider(); _components.AddInstance<FormDecoderProvider>(sessionStore); _components.AddInstance<IHttpSessionStore>(sessionStore); if (logWriter != null) _components.AddInstance<ILogWriter>(logWriter); _requestQueue = new RequestQueue(ProcessRequestWrapper); }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param> /// <param name="logWriter">The log writer.</param> /// <seealso cref="IFormDecoder"/> /// <seealso cref="FormDecoderProviders"/> /// <seealso cref="LogWriter"/> public HttpServer(FormDecoderProvider decoderProvider, ILogWriter logWriter) { Check.Require(decoderProvider, "decoderProvider"); Check.Require(logWriter, "logWriter"); _components = new ComponentProvider(); _components.AddInstance<FormDecoderProvider>(decoderProvider); _requestQueue = new RequestQueue(ProcessRequestWrapper); }
public void BlockingHandler(IHttpClientContext context0, IHttpRequest request, IHttpResponse response) { // UUID capsID; bool success; string path = request.Uri.PathAndQuery;//.TrimEnd('/'); if (path.Contains("5580")) { path = path.Replace("?:5580/", ""); } string pathd = HttpUtility.UrlDecode(path);//.TrimEnd('/'); LogInfo("_listener " + path + " from " + request.RemoteEndPoint); if (request.UriPath.EndsWith(".ico")) { response.Status = HttpStatusCode.NotFound; response.Send(); } var wrresp = new WriteLineToResponse(this, response); string botname = GetVariable(request, "bot", GetVariable(request, "botid", null)); ScriptExecutor _botClient = clientManager.GetScriptExecuter(botname); if (_botClient == null) { response.Status = HttpStatusCode.ServiceUnavailable; response.Send(); return; } // Micro-posterboard if (pathd.StartsWith("/posterboard")) { string slot = path; string value = ""; value = _botClient.getPosterBoard(slot) as string; if (value != null) if (value.Length > 0) { LogInfo(String.Format(" board response: {0} = {1}", slot, value)); } AddToBody(response, "<xml>"); AddToBody(response, "<slot>"); AddToBody(response, "<path>" + path + "</path>"); AddToBody(response, "<value>" + (value ?? "") + "</value>"); AddToBody(response, "</slot>"); AddToBody(response, "</xml>"); wrresp.response = null; response.Status = HttpStatusCode.OK; response.Send(); return; } bool useHtml = false; if (request.Method == "POST") { var fdp = new FormDecoderProvider(); fdp.Add(new MultipartDecoder()); fdp.Add(new UrlDecoder()); request.DecodeBody(fdp); } if (path.StartsWith("/?") || path.StartsWith("/test")) { useHtml = true; } if (DLRConsole.IsDougsMachine) { useHtml = true; } try { if (OverrideHandlers(request, response)) return; if (useHtml) { AddToBody(response, "<html>"); AddToBody(response, "<head>"); botname = GetVariable(request, "bot", _botClient.GetName()); AddToBody(response, "<title>" + botname + "</title>"); AddToBody(response, "</head>"); AddToBody(response, "<body>"); AddToBody(response, "<pre>"); foreach (var p in request.Param.AsEnumerable()) { foreach (var item in p.Values) { AddToBody(response, "" + p.Name + " = " + item); } } AddToBody(response, "</pre>"); AddToBody(response, "<a href='" + request.Uri.PathAndQuery + "'>" + request.Uri.PathAndQuery + "</a>"); AddToBody(response, "<pre>"); } string cmd = GetVariable(request, "cmd", "MeNe"); CmdResult res; // this is our default handler if (cmd != "MeNe") { res = _botClient.ExecuteXmlCommand(cmd + " " + GetVariable(request, "args", ""), request, wrresp.WriteLine); } else { try { InvokeAsMene(request, response, _botClient, pathd, wrresp); } catch (Exception exception) { LogInfo("InvokeAsMene exception: " + exception); } } if (useHtml) { AddToBody(response, "</pre>"); AddToBody(response, "</body>"); AddToBody(response, "</html>"); } } finally { wrresp.response = null; response.Status = HttpStatusCode.OK; try { response.Send(); } catch (Exception e) { LogInfo("Exception sening respose: " + e); } } }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param> /// <seealso cref="IFormDecoder"/> /// <seealso cref="FormDecoderProviders"/> public HttpServer(FormDecoderProvider decoderProvider) { Check.Require(decoderProvider, "decoderProvider"); _components = new ComponentFactory(); _components.AddInstance<FormDecoderProvider>(decoderProvider); }
/// <summary> /// Initializes a new instance of the <see cref="HttpServer"/> class. /// </summary> /// <param name="decoderProvider">Form decoders are used to convert different types of posted data to the <see cref="HttpInput"/> object types.</param> /// <param name="sessionStore">A session store is used to save and retrieve sessions</param> /// <param name="logWriter">The log writer.</param> /// <seealso cref="IFormDecoder"/> /// <seealso cref="FormDecoderProviders"/> /// <seealso cref="LogWriter"/> /// <seealso cref="IHttpSessionStore"/> public HttpServer(FormDecoderProvider decoderProvider, IHttpSessionStore sessionStore, ILogWriter logWriter) { Check.Require(decoderProvider, "decoderProvider"); Check.Require(sessionStore, "sessionStore"); _components = new ComponentFactory(); _components.AddInstance<FormDecoderProvider>(sessionStore); _components.AddInstance<IHttpSessionStore>(sessionStore); if (logWriter != null) _components.AddInstance<ILogWriter>(logWriter); }
/// <summary> /// Decode body into a form. /// </summary> /// <param name="providers">A list with form decoders.</param> /// <exception cref="InvalidDataException">If body contents is not valid for the chosen decoder.</exception> /// <exception cref="InvalidOperationException">If body is still being transferred.</exception> public void DecodeBody(FormDecoderProvider providers) { _form = providers.Decode(_headers["content-type"], _body, Encoding.UTF8); }
/// <summary> /// Decode body into a form. /// </summary> /// <param name="providers">A list with form decoders.</param> /// <exception cref="InvalidDataException">If body contents is not valid for the chosen decoder.</exception> /// <exception cref="InvalidOperationException">If body is still being transferred.</exception> public void DecodeBody(FormDecoderProvider providers) { if (_bodyBytesLeft > 0) throw new InvalidOperationException("Body transfer has not yet been completed."); Encoding encoding = null; string encodingStr = this.Headers["content-encoding"]; if (!String.IsNullOrEmpty(encodingStr)) { try { encoding = Encoding.GetEncoding(encodingStr); } catch { } } if (encoding == null) encoding = Encoding.UTF8; _form = providers.Decode(_headers["content-type"], _body, encoding); if (_form != HttpInput.Empty) _param.SetForm(_form); }