Exemplo n.º 1
0
        public void It_has_an_extension_method_to_write_the_body()
        {
            _formatter.WriteHttpBody(new Utf8String(HttpBody));

            var result = _formatter.Buffer;

            result.Should().ContainInOrder(_httpBodyInBytes);

            ManagedBufferPool <byte> .SharedByteBufferPool.ReturnBuffer(ref result);
        }
Exemplo n.º 2
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.º 3
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.º 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));
    }
Exemplo n.º 5
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));
    }