ストリームからHTTPリクエストを読み取るクラスです
Ejemplo n.º 1
0
        /// <summary>
        /// HTTPリクエストを解析します
        /// </summary>
        /// <param name="header">リクエスト</param>
        /// <returns>
        /// 解析できた場合はHTTPRequest、それ以外はnull
        /// </returns>
        private HTTPRequest ParseRequest(byte[] header)
        {
            HTTPRequest res    = null;
            var         stream = new MemoryStream(header);

            try {
                res = HTTPRequestReader.Read(stream);
            }
            catch (EndOfStreamException) {
            }
            stream.Close();
            return(res);
        }
 public override Guid?ParseChannelID(byte[] header)
 {
     using (var stream = new MemoryStream(header)) {
         var res = HTTPRequestReader.Read(stream);
         if (res != null)
         {
             return(Guid.Empty);
         }
         else
         {
             return(null);
         }
     }
 }
 public override IOutputStream Create(
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     AccessControlInfo access_control,
     Guid channel_id,
     byte[] header)
 {
     using (var stream = new MemoryStream(header)) {
         var req = HTTPRequestReader.Read(stream);
         return(new HTTPDummyOutputStream(
                    PeerCast,
                    input_stream,
                    output_stream,
                    remote_endpoint,
                    access_control,
                    req));
     }
 }
        public override Guid?ParseChannelID(byte[] header)
        {
            HTTPRequest res    = null;
            var         stream = new MemoryStream(header);

            try {
                res = HTTPRequestReader.Read(stream);
            }
            catch (EndOfStreamException) {
            }
            stream.Close();
            if (res != null)
            {
                return(Guid.Empty);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        private async Task Handshake(CancellationToken cancel_token)
        {
            var request = await HTTPRequestReader.ReadAsync(connection.Stream, cancel_token).ConfigureAwait(false);

            if (request == null)
            {
                new HTTPError(HttpStatusCode.BadRequest);
            }
            if (request.Method != "POST")
            {
                new HTTPError(HttpStatusCode.MethodNotAllowed);
            }
            Logger.Debug("POST requested");

            string encodings;

            if (request.Headers.TryGetValue("TRANSFER-ENCODING", out encodings))
            {
                var codings = encodings.Split(',')
                              .Select(token => token.Trim())
                              .Distinct()
                              .ToArray();
                if (codings.Length > 1 ||
                    codings[0].ToLowerInvariant() != "chunked")
                {
                    new HTTPError(HttpStatusCode.NotImplemented);
                }
                chunked = true;
                Logger.Debug("chunked encoding");
            }

            if (request.Headers.ContainsKey("CONTENT-TYPE"))
            {
                Logger.Debug("Content-Type: {0}", request.Headers["CONTENT-TYPE"]);
            }

            if (!request.Headers.TryGetValue("USER-AGENT", out clientName))
            {
                clientName = "";
            }
        }
Ejemplo n.º 6
0
        public override IOutputStream Create(
            Stream input_stream,
            Stream output_stream,
            EndPoint remote_endpoint,
            AccessControlInfo access_control,
            Guid channel_id,
            byte[] header)
        {
            HTTPRequest req    = null;
            var         stream = new MemoryStream(header);

            try {
                req = HTTPRequestReader.Read(stream);
            }
            catch (EndOfStreamException) {
            }
            return(new HTTPDummyOutputStream(
                       PeerCast,
                       input_stream,
                       output_stream,
                       remote_endpoint,
                       access_control,
                       req));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// HTTPリクエストを解析します
 /// </summary>
 /// <param name="header">リクエスト</param>
 /// <returns>
 /// 解析できた場合はHTTPRequest、それ以外はnull
 /// </returns>
 private HTTPRequest ParseRequest(byte[] header)
 {
     using (var stream = new MemoryStream(header)) {
         return(HTTPRequestReader.Read(stream));
     }
 }