コード例 #1
0
        static void WriteResponseForGetTime(HttpRequest request, HttpResponse response)
        {
            var body = new ResponseFormatter(response, formatBody: true);

            body.Format(@"<html><head><title>Time</title></head><body>{0:O}</body></html>", DateTime.UtcNow);

            WriteCommonHeaders(response, HttpVersion.V1_1, 200, "OK", keepAlive: false);
            var headers = new ResponseFormatter(response, formatBody: false);

            headers.Append("Content-Length : ");
            headers.Append(response.BodyLength);
            headers.AppendHttpNewLine();
            headers.AppendHttpNewLine();
        }
コード例 #2
0
        static void WriteResponseForHelloWorld(HttpRequest request, HttpResponse response)
        {
            var body = new ResponseFormatter(response, formatBody: true);

            body.Append("Hello, World");

            var headers = new ResponseFormatter(response, formatBody: false);

            headers.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
            headers.Append("Content-Length : ");
            headers.Append(response.BodyLength);
            headers.AppendHttpNewLine();
            headers.Append("Content-Type : text/plain; charset=UTF-8");
            headers.AppendHttpNewLine();
            headers.Append("Server : .NET Core Sample Server");
            headers.AppendHttpNewLine();
            headers.Append("Date : ");
            headers.Append(DateTime.UtcNow, 'R');
            headers.AppendHttpNewLine();
            headers.AppendHttpNewLine();
        }
コード例 #3
0
        void WriteResponseForPostJson(HttpRequest request, HttpResponse response)
        {
            // read request json
            int requestedCount;

            // TODO: this should not conver to span
            using (var dom = JsonObject.Parse(request.Body.ToSpan())) {
                requestedCount = (int)dom["Count"];
            }

            // write response JSON
            var jsonWriter = new JsonWriter <ResponseFormatter>(new ResponseFormatter(response, formatBody: true), prettyPrint: false);

            jsonWriter.WriteObjectStart();
            jsonWriter.WriteArrayStart();
            for (int i = 0; i < requestedCount; i++)
            {
                jsonWriter.WriteString("hello!");
            }
            jsonWriter.WriteArrayEnd();
            jsonWriter.WriteObjectEnd();

            // write headers
            var headers = new ResponseFormatter(response, formatBody: false);

            headers.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
            headers.Append("Content-Length : ");
            headers.Append(response.BodyLength);
            headers.AppendHttpNewLine();
            headers.Append("Content-Type : text/plain; charset=UTF-8");
            headers.AppendHttpNewLine();
            headers.Append("Server : .NET Core Sample Server");
            headers.AppendHttpNewLine();
            headers.Append("Date : ");
            headers.Append(DateTime.UtcNow, 'R');
            headers.AppendHttpNewLine();
            headers.AppendHttpNewLine();
        }