Exemplo n.º 1
0
    public void GlobalSetup()
    {
        _knownSingleValueResponseHeaders = new HttpResponseHeaders();

        _knownSingleValueResponseHeaders.Server      = "Value";
        _knownSingleValueResponseHeaders.Date        = "Value";
        _knownSingleValueResponseHeaders.ContentType = "Value";
        _knownSingleValueResponseHeaders.SetCookie   = "Value";

        _knownMultipleValueResponseHeaders = new HttpResponseHeaders();

        _knownMultipleValueResponseHeaders.Server      = new StringValues(new[] { "One", "Two" });
        _knownMultipleValueResponseHeaders.Date        = new StringValues(new[] { "One", "Two" });
        _knownMultipleValueResponseHeaders.ContentType = new StringValues(new[] { "One", "Two" });
        _knownMultipleValueResponseHeaders.SetCookie   = new StringValues(new[] { "One", "Two" });

        _unknownSingleValueResponseHeaders = new HttpResponseHeaders();
        _unknownSingleValueResponseHeaders.Append("One", "Value");
        _unknownSingleValueResponseHeaders.Append("Two", "Value");
        _unknownSingleValueResponseHeaders.Append("Three", "Value");
        _unknownSingleValueResponseHeaders.Append("Four", "Value");

        _unknownMultipleValueResponseHeaders = new HttpResponseHeaders();
        _unknownMultipleValueResponseHeaders.Append("One", new StringValues(new[] { "One", "Two" }));
        _unknownMultipleValueResponseHeaders.Append("Two", new StringValues(new[] { "One", "Two" }));
        _unknownMultipleValueResponseHeaders.Append("Three", new StringValues(new[] { "One", "Two" }));
        _unknownMultipleValueResponseHeaders.Append("Four", new StringValues(new[] { "One", "Two" }));

        _enumerator = new Http2HeadersEnumerator();
    }
Exemplo n.º 2
0
    public static void WriteStartStream(this PipeWriter writer, int streamId, DynamicHPackEncoder hpackEncoder, Http2HeadersEnumerator headers, byte[] headerEncodingBuffer, bool endStream, Http2Frame frame = null)
    {
        frame ??= new Http2Frame();
        frame.PrepareHeaders(Http2HeadersFrameFlags.NONE, streamId);

        var buffer = headerEncodingBuffer.AsSpan();
        var done   = HPackHeaderWriter.BeginEncodeHeaders(hpackEncoder, headers, buffer, out var length);

        frame.PayloadLength = length;

        if (done)
        {
            frame.HeadersFlags = Http2HeadersFrameFlags.END_HEADERS;
        }

        if (endStream)
        {
            frame.HeadersFlags |= Http2HeadersFrameFlags.END_STREAM;
        }

        Http2FrameWriter.WriteHeader(frame, writer);
        writer.Write(buffer.Slice(0, length));

        while (!done)
        {
            frame.PrepareContinuation(Http2ContinuationFrameFlags.NONE, streamId);

            done = HPackHeaderWriter.ContinueEncodeHeaders(hpackEncoder, headers, buffer, out length);
            frame.PayloadLength = length;

            if (done)
            {
                frame.ContinuationFlags = Http2ContinuationFrameFlags.END_HEADERS;
            }

            Http2FrameWriter.WriteHeader(frame, writer);
            writer.Write(buffer.Slice(0, length));
        }
    }