Example #1
0
        public byte[] OnWriteData(WebRequest request, WebResponse response)
        {
            HStream stream = null;

            if (request is Http2Request)
            {
                var http2Request = (Http2Request)request;

                if (http2Request.streamId != 0 &&
                    streams.ContainsKey(http2Request.streamId))
                {
                    stream = streams[http2Request.streamId];
                }
            }

            if (response is Http2SettingResponse)
            {
                return(Http2FrameBuilder.Setting());
            }
            else if (response is Http2PingResponse)
            {
                return(Http2FrameBuilder.Pong((Http2PingResponse)response));
            }
            else if (response is Http.HttpResponse)
            {
                var headerResponse = stream.hpack.BuildResponse((Http.HttpResponse)response);
            }

            return(new byte[] { });
        }
Example #2
0
        public IEnumerable <WebRequest> OnReceiveData(ArraySegment <byte> data)
        {
            var header = Http2Parser.ParseHeader(data);

            if (header == null)
            {
                yield break;
            }

            HStream stream = null;

            if (header.streamId != 0 &&
                streams.ContainsKey(header.streamId))
            {
                stream = streams[header.streamId];
            }

            if (header.type == Http2FrameType.Setting)
            {
                yield return(new Http2SettingRequest());
            }
            else if (header.type == Http2FrameType.Headers)
            {
                var headers = Http2Parser.ParseHeaders(
                    header, new ArraySegment <byte>(data.Array, data.Offset + 9, data.Count - 9));

                if (headers == null)
                {
                    yield break;
                }

                if (streams.ContainsKey(header.streamId) == false)
                {
                    stream = streams[header.streamId] = new HStream();
                }
            }
            else if (header.type == Http2FrameType.Ping)
            {
                var ping = Http2Parser.ParsePing(
                    header, new ArraySegment <byte>(data.Array, data.Offset + 9, data.Count - 9));

                if (ping == null)
                {
                    yield break;
                }

                yield return(ping);
            }
            else if (header.type == Http2FrameType.Data)
            {
            }
        }