1
1
'use strict' ;
2
- require ( '../common' ) ;
2
+ const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
4
const http = require ( 'http' ) ;
5
5
6
6
// Verify that ServerResponse.writeHead() works as setHeader.
7
7
// Issue 5036 on github.
8
8
9
- const s = http . createServer ( function ( req , res ) {
9
+ const s = http . createServer ( common . mustCall ( ( req , res ) => {
10
10
res . setHeader ( 'test' , '1' ) ;
11
11
12
12
// toLowerCase() is used on the name argument, so it must be a string.
@@ -32,18 +32,23 @@ const s = http.createServer(function(req, res) {
32
32
assert . ok ( threw , 'Undefined value should throw' ) ;
33
33
34
34
res . writeHead ( 200 , { Test : '2' } ) ;
35
+
36
+ assert . throws ( ( ) => {
37
+ res . writeHead ( 100 , { } ) ;
38
+ } , / ^ E r r o r : C a n ' t r e n d e r h e a d e r s a f t e r t h e y a r e s e n t t o t h e c l i e n t $ / ) ;
39
+
35
40
res . end ( ) ;
36
- } ) ;
41
+ } ) ) ;
37
42
38
- s . listen ( 0 , runTest ) ;
43
+ s . listen ( 0 , common . mustCall ( runTest ) ) ;
39
44
40
45
function runTest ( ) {
41
- http . get ( { port : this . address ( ) . port } , function ( response ) {
42
- response . on ( 'end' , function ( ) {
46
+ http . get ( { port : this . address ( ) . port } , common . mustCall ( ( response ) => {
47
+ response . on ( 'end' , common . mustCall ( ( ) => {
43
48
assert . strictEqual ( response . headers [ 'test' ] , '2' ) ;
44
49
assert . notStrictEqual ( response . rawHeaders . indexOf ( 'Test' ) , - 1 ) ;
45
50
s . close ( ) ;
46
- } ) ;
51
+ } ) ) ;
47
52
response . resume ( ) ;
48
- } ) ;
53
+ } ) ) ;
49
54
}
0 commit comments