-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at streaming http response (#16)
- Loading branch information
1 parent
20714fe
commit 2696658
Showing
6 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters