コード例 #1
0
        public static void AppendHttpRequestLine <TFormatter>(this TFormatter formatter, Parser.Http.Method method, Parser.Http.Version version, string path) where TFormatter : ITextBufferWriter
        {
            if (formatter.SymbolTable == SymbolTable.InvariantUtf8)
            {
                switch (method)
                {
                case Parser.Http.Method.Get: formatter.AppendBytes(s_GetUtf8); break;

                case Parser.Http.Method.Post: formatter.AppendBytes(s_PostUtf8); break;

                case Parser.Http.Method.Put: formatter.AppendBytes(s_PutUtf8); break;

                case Parser.Http.Method.Delete: formatter.AppendBytes(s_DeleteUtf8); break;

                default: formatter.Append(method.ToString()); formatter.Append(' '); break;
                }

                formatter.Append(path);

                switch (version)
                {
                case Parser.Http.Version.Http10: formatter.AppendBytes(s_Http10Utf8); break;

                case Parser.Http.Version.Http11: formatter.AppendBytes(s_Http11Utf8); break;

                //case HttpVersion.V2_0: formatter.AppendBytes(s_Http20Utf8); break;
                default: throw new ArgumentException(nameof(version));
                }
            }
            else
            {
                formatter.Append(method.ToString());
                formatter.Append(' ');
                formatter.Append(path);
                formatter.Append(' ');
                switch (version)
                {
                case Parser.Http.Version.Http10: formatter.Append(Http10); break;

                case Parser.Http.Version.Http11: formatter.Append(Http11); break;

                //case HttpVersion.V2_0: formatter.Append(Http20); break;
                default: throw new ArgumentException(nameof(version));
                }
                formatter.AppendHttpNewLine();
            }
        }
コード例 #2
0
        public static void AppendHttpStatusLine <TFormatter>(this TFormatter formatter, Parser.Http.Version version, int statusCode, Utf8Span reasonCode) where TFormatter : ITextBufferWriter
        {
            switch (version)
            {
            case Parser.Http.Version.Http10: formatter.Append(Http10); break;

            case Parser.Http.Version.Http11: formatter.Append(Http11); break;

            //case HttpVersion.V2_0: formatter.Append(Http20); break;
            default: throw new ArgumentException(nameof(version));
            }

            formatter.Append(" ");
            formatter.Append(statusCode);
            formatter.Append(" ");
            formatter.Append(reasonCode);
            formatter.AppendHttpNewLine();
        }