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")); }
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); }
// TODO: this should not be here. Also, this should not allocate protected static void WriteCommonHeaders( BufferFormatter formatter, string version, string statuCode, string reasonCode, bool keepAlive) { var currentTime = DateTime.UtcNow; formatter.WriteHttpStatusLine( new Utf8String(version), new Utf8String(statuCode), new Utf8String(reasonCode)); formatter.WriteHttpHeader(new Utf8String("Date"), new Utf8String(currentTime.ToString("R"))); formatter.WriteHttpHeader(new Utf8String("Server"), new Utf8String(".NET Core Sample Serve")); formatter.WriteHttpHeader(new Utf8String("Last-Modified"), new Utf8String(currentTime.ToString("R"))); formatter.WriteHttpHeader(new Utf8String("Content-Type"), new Utf8String("text/html; charset=UTF-8")); if (!keepAlive) { formatter.WriteHttpHeader(new Utf8String("Connection"), new Utf8String("close")); } }