Add http.Context
This commit is contained in:
parent
8ba0ebd84c
commit
053de35d33
3 changed files with 21 additions and 7 deletions
|
@ -2,6 +2,8 @@ const std = @import("std");
|
||||||
|
|
||||||
pub const Connection = struct {
|
pub const Connection = struct {
|
||||||
pub const Id = u64;
|
pub const Id = u64;
|
||||||
|
pub const Writer = std.net.Stream.Writer;
|
||||||
|
pub const Reader = std.net.Stream.Reader;
|
||||||
|
|
||||||
id: Id,
|
id: Id,
|
||||||
address: std.net.Address,
|
address: std.net.Address,
|
||||||
|
|
|
@ -29,6 +29,18 @@ pub const Request = struct {
|
||||||
body: ?[]const u8 = null,
|
body: ?[]const u8 = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Context = struct {
|
||||||
|
arena_alloc: std.mem.Allocator,
|
||||||
|
request: *const Request,
|
||||||
|
connection: *const Connection,
|
||||||
|
|
||||||
|
const Writer = ResponseStream(Connection.Writer);
|
||||||
|
|
||||||
|
pub fn openResponse(self: *Context, headers: *const Headers, status: Status) !Writer {
|
||||||
|
return try response_stream.open(self.arena_alloc, self.connection.stream.writer(), headers, status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = conn;
|
_ = conn;
|
||||||
_ = response_stream;
|
_ = response_stream;
|
||||||
|
|
|
@ -5,7 +5,7 @@ const Status = http.Status;
|
||||||
const Headers = http.Headers;
|
const Headers = http.Headers;
|
||||||
|
|
||||||
const chunk_size = 16 * 1024;
|
const chunk_size = 16 * 1024;
|
||||||
pub fn openResponse(
|
pub fn open(
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
headers: *const Headers,
|
headers: *const Headers,
|
||||||
|
@ -176,7 +176,7 @@ const _tests = struct {
|
||||||
defer headers.deinit();
|
defer headers.deinit();
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
@ -206,7 +206,7 @@ const _tests = struct {
|
||||||
try headers.put("Content-Type", "text/plain");
|
try headers.put("Content-Type", "text/plain");
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
@ -237,7 +237,7 @@ const _tests = struct {
|
||||||
try headers.put("Content-Type", "text/plain");
|
try headers.put("Content-Type", "text/plain");
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
@ -267,7 +267,7 @@ const _tests = struct {
|
||||||
try headers.put("Content-Type", "text/plain");
|
try headers.put("Content-Type", "text/plain");
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
@ -301,7 +301,7 @@ const _tests = struct {
|
||||||
try headers.put("Content-Type", "text/plain");
|
try headers.put("Content-Type", "text/plain");
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
@ -342,7 +342,7 @@ const _tests = struct {
|
||||||
try headers.put("Content-Type", "text/plain");
|
try headers.put("Content-Type", "text/plain");
|
||||||
|
|
||||||
{
|
{
|
||||||
var stream = try openResponse(
|
var stream = try open(
|
||||||
std.testing.allocator,
|
std.testing.allocator,
|
||||||
test_stream.writer(),
|
test_stream.writer(),
|
||||||
&headers,
|
&headers,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue