public HeaderReader( HPack.Decoder hpackDecoder, uint maxFrameSize, uint maxHeaderFieldsSize, IReadableByteStream reader ) { this.reader = reader; this.hpackDecoder = hpackDecoder; this.maxFrameSize = maxFrameSize; this.maxHeaderFieldsSize = maxHeaderFieldsSize; }
/// <summary> /// 使用给定的解码器解码整个头块片段。 /// </summary> /// <param name="decoder"></param> /// <param name="buffer"></param> /// <param name="maxHeaderFieldsSize"></param> /// <param name="headers"></param> /// <returns></returns> public static DecodeFragmentResult DecodeHeaderBlockFragment( this HPack.Decoder decoder, ArraySegment <byte> buffer, uint maxHeaderFieldsSize, List <HeaderField> headers) { int offset = buffer.Offset; int length = buffer.Count; uint headersSize = 0; try { while (length > 0) { var segment = new ArraySegment <byte>(buffer.Array, offset, length); var consumed = decoder.Decode(segment); offset += consumed; length -= consumed; if (decoder.Done) { headersSize += (uint)decoder.HeaderSize; if (headersSize > maxHeaderFieldsSize) { headersSize -= (uint)decoder.HeaderSize; return(new DecodeFragmentResult { Status = DecodeStatus.MaxHeaderListSizeExceeded, HeaderFieldsSize = headersSize, }); } headers.Add(decoder.HeaderField); } } } catch (Exception) { return(new DecodeFragmentResult { Status = DecodeStatus.InvalidHeaderBlockFragment, HeaderFieldsSize = headersSize, }); } return(new DecodeFragmentResult { Status = DecodeStatus.Success, HeaderFieldsSize = headersSize, }); }
public static NameValueCollection UnpackHeaders(byte[] data, int maxHeaderSize, int maxHeaderTableSize) { var headers = new NameValueCollection(); // Decode Header Block Fragments var hpackDecoder = new HPack.Decoder(maxHeaderSize, maxHeaderTableSize); using (var binReader = new BinaryReader(new MemoryStream(data))) { hpackDecoder.Decode(binReader, (name, value, sensitive) => headers.Add( System.Text.Encoding.ASCII.GetString(name), System.Text.Encoding.ASCII.GetString(value))); hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process. } return(headers); }
public static NameValueCollection UnpackHeaders (byte[] data, int maxHeaderSize, int maxHeaderTableSize) { var headers = new NameValueCollection (); // Decode Header Block Fragments var hpackDecoder = new HPack.Decoder (maxHeaderSize, maxHeaderTableSize); using(var binReader = new BinaryReader (new MemoryStream (data))) { hpackDecoder.Decode(binReader, (name, value, sensitive) => headers.Add ( System.Text.Encoding.ASCII.GetString (name), System.Text.Encoding.ASCII.GetString (value))); hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process. } return headers; }