public HttpTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback callback) { Server = server; IOStream = stream; Socket = socket; ConnectionCallback = callback; write_ops = new Queue<IWriteOperation> (); stream.ReadUntil ("\r\n\r\n", OnHeaders); }
private void HandleEvents(IntPtr fd, EpollEvents events) { while (true) { Socket s = null; try { s = Socket.Accept (); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; throw se; } catch { throw; } IOStream iostream = new IOStream (s, IOLoop); HttpTransaction.BeginTransaction (this, iostream, s, callback); } }
private void OnHeaders(IOStream stream, byte [] data) { string h = Encoding.ASCII.GetString (data); StringReader reader = new StringReader (h); string verb; string path; string version; string line = reader.ReadLine (); ParseStartLine (line, out verb, out path, out version); HttpHeaders headers = new HttpHeaders (); headers.Parse (reader); Request = new HttpRequest (this, headers, verb, path, Version_1_1_Supported (version)); Response = new HttpResponse (this, Encoding.ASCII); if (headers.ContentLength != null && headers.ContentLength > 0) { stream.ReadBytes ((int) headers.ContentLength, OnBody); return; } Server.IOLoop.QueueTransaction (this); }
private void OnBody(IOStream stream, byte [] data) { if (Request.Method == "POST") { string ct = Request.Headers ["Content-Type"]; if (ct == "application/x-www-form-urlencoded") OnWwwFormData (data); else if (ct == "multipart/form-data") OnMultiPartFormData (data); } Server.IOLoop.QueueTransaction (this); }
public static void BeginTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback cb) { HttpTransaction transaction = new HttpTransaction (server, stream, socket, cb); }
private void HandleIOEvents(Loop loop, IOWatcher watcher, int revents) { while (true) { Socket s = null; try { s = Socket.Accept (); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; throw se; } catch { throw; } IOStream iostream = new IOStream (s, IOLoop); transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback)); } }
public void Write(IOStream stream) { stream.SendFile (file, callback); }
private void OnWwwFormData(IOStream stream, byte [] data) { // // The best I can tell, you can't actually set the content-type of // the url-encoded form data. Looking at the source of apache // seems to confirm this. So for now I wont worry about the // encoding type and I'll just use ASCII. // string post = Encoding.ASCII.GetString (data); if (!String.IsNullOrEmpty (post)) { // TODO: pass this to the encoder to populate DataDictionary post_data = HttpUtility.ParseUrlEncodedData (post); if (post_data != null) Request.SetWwwFormData (post_data); } IOStream.DisableReading (); Server.RunTransaction (this); }
private void OnHeaders(IOStream stream, byte [] data) { string h = Encoding.ASCII.GetString (data); StringReader reader = new StringReader (h); string verb; string path; string version; string line = reader.ReadLine (); ParseStartLine (line, out verb, out path, out version); HttpHeaders headers = new HttpHeaders (); headers.Parse (reader); Request = new HttpRequest (this, headers, verb, path, Version_1_1_Supported (version)); Response = new HttpResponse (this, Encoding.ASCII); if (headers.ContentLength != null && headers.ContentLength > 0) { long cl = (long) headers.ContentLength; if (cl < MAX_BUFFERED_CONTENT_LENGTH) { HandleBody (); return; } else { HandleLargeBody (); return; } } stream.DisableReading (); Server.RunTransaction (this); }
private void OnClose(IOStream stream) { }