public IObservable<Unit> Begin()
        {
            return Observable.CreateWithDisposable<Unit>(o =>
            {
                // would be nice some day to parse the request with a fancy state machine
                // for lower memory usage.
                Trace.Write("Beginning request.");
                return socket.ReadHeaders().Subscribe(headerBuffers =>
                    {
                        bodyDataReadWithHeaders = headerBuffers.Last.Value;
                        headerBuffers.RemoveLast();

                        var reader = new StringReader(headerBuffers.GetString());

                        this.requestLine = reader.ReadRequestLine();
                        Headers = reader.ReadHeaders();

                        reader.Dispose(); // necessary?
                        Trace.Write("Request began.");
                    },
                    e =>
                    {
                        o.OnError(e);
                    },
                    () =>
                    {
                        o.OnCompleted();
                    });
            });
        }
Beispiel #2
0
 public KayakRequest(ISocket socket, HttpRequestLine requestLine, IDictionary<string, IEnumerable<string>> headers, IDictionary<string, object> context, ArraySegment<byte> bodyDataReadWithHeaders)
 {
     this.socket = socket;
     Method = requestLine.Verb;
     Uri = requestLine.RequestUri;
     Headers = headers;
     Items = context;
     this.bodyDataReadWithHeaders = bodyDataReadWithHeaders;
 }
Beispiel #3
0
        internal static HttpRequestLine ReadRequestLine(this TextReader reader)
        {
            string statusLine = reader.ReadLine();

            if (string.IsNullOrEmpty(statusLine))
                throw new Exception("Could not parse request status.");

            var tokens = statusLine.Split(' ').Where(s => !string.IsNullOrEmpty(s)).ToArray();

            if (tokens.Length != 3 && tokens.Length != 2)
                throw new Exception("Expected 2 or 3 tokens in request line.");

            var requestLine = new HttpRequestLine();

            return new HttpRequestLine()
                {
                    Verb = tokens[0],
                    RequestUri = tokens[1],
                    HttpVersion = tokens.Length == 3 ? tokens[2] : "HTTP/1.0"
                };
        }