@@ -414,33 +414,6 @@ const handlerWithCustomProps: HandlerFunction<any, RequestContext> = (
414
414
res . send ( { status : 'ok' } ) ;
415
415
} ;
416
416
417
- const testResponseMethods : HandlerFunction < any , RequestContext > = (
418
- req ,
419
- res
420
- ) => {
421
- res . status ( 201 ) ;
422
- res . header ( 'X-Custom' , 'value' ) ;
423
- res . getHeader ( 'X-Custom' ) ;
424
- res . hasHeader ( 'X-Custom' ) ;
425
- res . removeHeader ( 'X-Custom' ) ;
426
- res . send ( { data : 'raw' } ) ;
427
- res . json ( { data : 'json' } ) ;
428
- res . html ( '<div>html</div>' ) ;
429
- res . redirect ( '/new-location' ) ;
430
- res . redirect ( 301 , '/permanent-location' ) ;
431
- res . type ( 'json' ) ;
432
- res . cookie ( 'session' , 'value' , { httpOnly : true } ) ;
433
- res . clearCookie ( 'session' ) ;
434
- res . cache ( 3600 ) ;
435
- res . cache ( true , true ) ;
436
- res . cors ( {
437
- origin : '*' ,
438
- methods : 'GET, POST' ,
439
- headers : 'Content-Type' ,
440
- } ) ;
441
- res . error ( 400 , 'Bad Request' ) ;
442
- } ;
443
-
444
417
const testRequestProperties : HandlerFunction < any , RequestContext > = (
445
418
req ,
446
419
res
@@ -469,13 +442,50 @@ const testRequestProperties: HandlerFunction<any, RequestContext> = (
469
442
req . log . fatal ( 'fatal message' ) ;
470
443
} ;
471
444
445
+ const testResponseMethods : HandlerFunction < any , RequestContext > = (
446
+ req ,
447
+ res
448
+ ) => {
449
+ res
450
+ . status ( 201 )
451
+ . header ( 'X-Custom' , 'value' )
452
+ . type ( 'json' )
453
+ . cors ( {
454
+ origin : '*' ,
455
+ methods : 'GET, POST' ,
456
+ headers : 'Content-Type' ,
457
+ } )
458
+ . cookie ( 'session' , 'value' , { httpOnly : true } )
459
+ . cache ( 3600 )
460
+ . etag ( true )
461
+ . modified ( new Date ( ) ) ;
462
+
463
+ expectType < string > ( res . getHeader ( 'X-Custom' ) ) ;
464
+ expectType < { [ key : string ] : string } > ( res . getHeaders ( ) ) ;
465
+ expectType < boolean > ( res . hasHeader ( 'X-Custom' ) ) ;
466
+ res . removeHeader ( 'X-Custom' ) ;
467
+
468
+ res . send ( { data : 'raw' } ) ;
469
+ res . json ( { data : 'json' } ) ;
470
+ res . jsonp ( { data : 'jsonp' } ) ;
471
+ res . html ( '<div>html</div>' ) ;
472
+ res . sendStatus ( 204 ) ;
473
+
474
+ res . redirect ( '/new-location' ) ;
475
+ res . redirect ( 301 , '/permanent-location' ) ;
476
+
477
+ res . clearCookie ( 'session' ) ;
478
+
479
+ res . error ( 400 , 'Bad Request' ) ;
480
+ res . error ( 'Error message' ) ;
481
+ } ;
482
+
472
483
const testErrorHandlingMiddleware : ErrorHandlingMiddleware = async (
473
484
error ,
474
485
req ,
475
486
res ,
476
487
next
477
488
) => {
478
- // Test that we can return different types
479
489
if ( error . message === 'sync' ) {
480
490
return { message : 'handled synchronously' } ;
481
491
}
0 commit comments