예제 #1
0
        public HttpHeader(ReadOnlySpan <byte> name, string value)
        {
            int length = name.Length + value.Length + 3;

            _utf8 = new byte[length];
            var utf8 = _utf8.AsSpan();

            name.CopyTo(_utf8);
            _utf8[name.Length] = (byte)':';

            utf8 = utf8.Slice(name.Length + 1);
            if (!Transcoder.TryUtf16ToAscii(value.AsSpan(), utf8, out _))
            {
                throw new Exception("value is not ASCII");
            }
            _utf8[length - 2] = (byte)'\r';
            _utf8[length - 1] = (byte)'\n';
        }
예제 #2
0
        public HttpHeader(string name, string value)
        {
            int length = name.Length + value.Length + 3;

            _utf8 = new byte[length];
            var utf8 = _utf8.AsSpan();

            if (!Transcoder.TryUtf16ToAscii(name.AsSpan(), utf8, out int written))
            {
                throw new Exception("name is not ASCII");
            }
            _utf8[written] = (byte)':';
            utf8           = utf8.Slice(written + 1);
            if (!Transcoder.TryUtf16ToAscii(value.AsSpan(), utf8, out written))
            {
                throw new Exception("name or value is not ASCII");
            }
            _utf8[length - 2] = (byte)'\r';
            _utf8[length - 1] = (byte)'\n';
        }