| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Text; |
| | | 6 | | |
| | | 7 | | namespace System.Net.Http.QPack |
| | | 8 | | { |
| | | 9 | | internal readonly struct HeaderField |
| | | 10 | | { |
| | | 11 | | // https://quicwg.org/base-drafts/draft-ietf-quic-http.html#section-4.1.1.3-1 |
| | | 12 | | // public for internal use in aspnetcore |
| | | 13 | | public const int RfcOverhead = 32; |
| | | 14 | | |
| | | 15 | | public HeaderField(byte[] name, byte[] value) |
| | 0 | 16 | | { |
| | 0 | 17 | | Debug.Assert(name.Length > 0); |
| | | 18 | | |
| | 0 | 19 | | Name = name; |
| | 0 | 20 | | Value = value; |
| | 0 | 21 | | } |
| | | 22 | | |
| | 0 | 23 | | public byte[] Name { get; } |
| | | 24 | | |
| | 0 | 25 | | public byte[] Value { get; } |
| | | 26 | | |
| | | 27 | | public int Length => GetLength(Name.Length, Value.Length); |
| | | 28 | | |
| | | 29 | | public static int GetLength(int nameLength, int valueLength) => nameLength + valueLength + RfcOverhead; |
| | | 30 | | |
| | | 31 | | public override string ToString() |
| | 0 | 32 | | { |
| | 0 | 33 | | if (Name != null) |
| | 0 | 34 | | { |
| | 0 | 35 | | return Encoding.ASCII.GetString(Name) + ": " + Encoding.ASCII.GetString(Value); |
| | | 36 | | } |
| | | 37 | | else |
| | 0 | 38 | | { |
| | 0 | 39 | | return "<empty>"; |
| | | 40 | | } |
| | 0 | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | |