Exemplo n.º 1
0
 public Request(HttpRequest req)
     : base(req.Connection)
 {
     this.headers = req.Headers;
         this.method = req.Method;
         this.path = req.Path;
         this.query = req.Query;
         this.version = req.Version;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the request.
        /// </summary>
        /// <param name="req">The request.</param>
        public void WriteRequest(HttpRequest req)
        {
            // request line
            WriteRequestLine(new HttpRequestLine() { Method = req.Method, Path = req.Path, Query = req.Query, Version = "HTTP/1.1" });

            // headers
            foreach (HttpHeader header in req.Headers) {
                WriteHeader(header);
            }

            // end of headers
            writer.WriteLine();
            writer.Flush();

            // data
            //if (req.Buffer.Length > 0) {
            //    byte[] data = req.Buffer.ToArray();
            //    writer.BaseStream.Write(data, 0, data.Length);
            //}
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the HTTP request from the stream with the provided stream.
        /// </summary>
        /// <returns></returns>
        public HttpRequest ReadRequest()
        {
            // request line
            HttpRequestLine reqLine = ReadRequestLine();

            // create request
            HttpRequest req = new HttpRequest(transaction);
            req.Path = reqLine.Path;
            req.Method = reqLine.Method;
            req.Query = reqLine.Query;

            // headers
            req.Headers = ReadHeaders();

            // body
            object contentLength = req.Headers["Content-Length"];

            if (contentLength != null) {
                byte[] data = new byte[(int)contentLength];
                reader.BaseStream.Read(data, 0, (int)contentLength);
            }

            return req;
        }