mirror of
https://github.com/denoland/deno.git
synced 2025-10-01 06:31:15 +00:00
First pass at streaming http response (denoland/deno_std#16)
Original: 269665873a
This commit is contained in:
parent
579b92de59
commit
f6dae45cd2
6 changed files with 121 additions and 17 deletions
58
http_test.ts
Normal file
58
http_test.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
// Copyright 2010 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Ported from
|
||||
// https://github.com/golang/go/blob/master/src/net/http/responsewrite_test.go
|
||||
|
||||
import {
|
||||
test,
|
||||
assert,
|
||||
assertEqual
|
||||
} from "https://deno.land/x/testing/testing.ts";
|
||||
|
||||
import {
|
||||
listenAndServe,
|
||||
ServerRequest,
|
||||
setContentLength,
|
||||
Response
|
||||
} from "./http";
|
||||
import { Buffer } from "./buffer";
|
||||
import { BufWriter } from "./bufio";
|
||||
|
||||
interface ResponseTest {
|
||||
response: Response;
|
||||
raw: string;
|
||||
}
|
||||
|
||||
const responseTests: ResponseTest[] = [
|
||||
// Default response
|
||||
{
|
||||
response: {},
|
||||
raw: "HTTP/1.1 200 OK\r\n" + "\r\n"
|
||||
},
|
||||
// HTTP/1.1, chunked coding; empty trailer; close
|
||||
{
|
||||
response: {
|
||||
status: 200,
|
||||
body: new Buffer(new TextEncoder().encode("abcdef"))
|
||||
},
|
||||
|
||||
raw:
|
||||
"HTTP/1.1 200 OK\r\n" +
|
||||
"transfer-encoding: chunked\r\n\r\n" +
|
||||
"6\r\nabcdef\r\n0\r\n\r\n"
|
||||
}
|
||||
];
|
||||
|
||||
test(async function responseWrite() {
|
||||
for (const testCase of responseTests) {
|
||||
const buf = new Buffer();
|
||||
const bufw = new BufWriter(buf);
|
||||
const request = new ServerRequest();
|
||||
request.w = bufw;
|
||||
|
||||
await request.respond(testCase.response);
|
||||
assertEqual(buf.toString(), testCase.raw);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue