示例#1
0
        // TODO (pri 2): it would be good if this could advance and flush instead demanding larger and larger buffers.
        protected override void WriteRequestLineAndHeaders(PipeWriter writer, ref T arguments)
        {
            Span<byte> memory = writer.GetSpan();
            BufferWriter bufferWriter = memory.AsHttpWriter();
            bufferWriter.Enlarge = (int desiredSize) =>
            {
                return writer.GetMemory(desiredSize);
            };

            bufferWriter.WriteRequestLine(Verb, Http.Version.Http11, arguments.RequestPath);

            int headersStart = bufferWriter.WrittenCount;
            WriteXmsHeaders(ref bufferWriter, ref arguments);
            Span<byte> headersBuffer = bufferWriter.Written.Slice(headersStart);

            var authenticationHeader = new StorageAuthorizationHeader()
            {
                // TODO (pri 1): the hash is not thread safe. is that OK?
                Hash = arguments.Client.Hash,
                HttpVerb = AsString(Verb),
                AccountName = arguments.Client.AccountName,
                CanonicalizedResource = arguments.CanonicalizedResource,
                // TODO (pri 1): this allocation should be eliminated
                CanonicalizedHeaders = headersBuffer.ToArray(),
                ContentLength = arguments.ContentLength
            };
            // TODO (pri 3): the default should be defaulted
            bufferWriter.WriteHeader("Authorization", authenticationHeader, default);

            WriteOtherHeaders(ref bufferWriter, ref arguments);
            bufferWriter.WriteEoh();

            writer.Advance(bufferWriter.WrittenCount);
        }