Exemplo n.º 1
0
 static void WriteResponseForGetTime(BufferFormatter formatter, HttpRequestLine request)
 {
     // TODO: this needs to not allocate
     var body = string.Format(@"<html><head><title>Time</title></head><body>{0}</body></html>", DateTime.UtcNow.ToString("O"));
     WriteCommonHeaders(formatter, "1.1", "200", "Ok", keepAlive: false);
     // TOOD: this needs to not allocate
     formatter.WriteHttpHeader(new Utf8String("Content-Length"), new Utf8String(body.Length.ToString()));
     formatter.EndHttpHeaderSection();
     formatter.WriteHttpBody(new Utf8String(body));
 }
Exemplo n.º 2
0
 private static void WriteResponseForHelloWorld(BufferFormatter formatter)
 {
     formatter.WriteHttpStatusLine(new Utf8String("1.1"), new Utf8String("200"), new Utf8String("Ok"));
     formatter.WriteHttpHeader(new Utf8String("Content-Length"), new Utf8String("12"));
     formatter.WriteHttpHeader(new Utf8String("Content-Type"), new Utf8String("text/plain; charset=UTF-8"));
     formatter.WriteHttpHeader(new Utf8String("Server"), new Utf8String(".NET Core Sample Serve"));
     // TODO: this needs to not allocate
     formatter.WriteHttpHeader(new Utf8String("Date"), new Utf8String(DateTime.UtcNow.ToString("R")));
     formatter.EndHttpHeaderSection();
     formatter.WriteHttpBody(new Utf8String("Hello, World"));
 }
Exemplo n.º 3
0
 private static HttpServerBuffer CreateResponseForHelloWorld()
 {
     var formatter = new BufferFormatter(1024, FormattingData.InvariantUtf8);
     formatter.WriteHttpStatusLine(new Utf8String("1.1"), new Utf8String("200"), new Utf8String("Ok"));
     formatter.WriteHttpHeader(new Utf8String("Content-Length"), new Utf8String("12"));
     formatter.WriteHttpHeader(new Utf8String("Content-Type"), new Utf8String("text/plain; charset=UTF-8"));
     formatter.WriteHttpHeader(new Utf8String("Server"), new Utf8String(".NET Core Sample Serve"));
     formatter.WriteHttpHeader(new Utf8String("Date"), new Utf8String(DateTime.UtcNow.ToString("R")));
     formatter.EndHttpHeaderSection();
     formatter.WriteHttpBody(new Utf8String("Hello, World"));
     return new HttpServerBuffer(formatter.Buffer, formatter.CommitedByteCount, BufferPool.Shared);
 }
Exemplo n.º 4
0
    static HttpServerBuffer CreateResponseForGetTime(HttpRequestLine request)
    {
        var body = string.Format(@"<html><head><title>Time</title></head><body>{0}</body></html>", DateTime.UtcNow.ToString("O"));
        var formatter = new BufferFormatter(1024, FormattingData.InvariantUtf8);

        WriteCommonHeaders(formatter, "1.1", "200", "Ok", request.IsKeepAlive());
        formatter.WriteHttpHeader(new Utf8String("Content-Length"), new Utf8String(body.Length.ToString()));
        formatter.EndHttpHeaderSection();

        formatter.WriteHttpBody(new Utf8String(body));

        return new HttpServerBuffer(formatter.Buffer, formatter.CommitedByteCount, BufferPool.Shared);
    }