@@ -958,57 +958,57 @@ describe('options.baseUrl', () => {
958
958
959
959
it ( 'uses baseUrl option without trailing slash and uri is prefixed with a slash' , async ( ) => {
960
960
961
- const promise = Wreck . request ( 'get' , '/foo' , { baseUrl : 'http://localhost' } ) ;
961
+ const promise = Wreck . request ( 'get' , '/foo' , { baseUrl : 'http://localhost:0 ' } ) ;
962
962
await expect ( promise ) . to . reject ( ) ;
963
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
963
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
964
964
expect ( promise . req . path ) . to . equal ( '/foo' ) ;
965
965
} ) ;
966
966
967
967
it ( 'uses baseUrl option with trailing slash and uri is prefixed without a slash' , async ( ) => {
968
968
969
- const promise = Wreck . request ( 'get' , 'foo' , { baseUrl : 'http://localhost/' } ) ;
969
+ const promise = Wreck . request ( 'get' , 'foo' , { baseUrl : 'http://localhost:0 /' } ) ;
970
970
await expect ( promise ) . to . reject ( ) ;
971
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
971
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
972
972
expect ( promise . req . path ) . to . equal ( '/foo' ) ;
973
973
} ) ;
974
974
975
975
it ( 'uses baseUrl option without trailing slash and uri is prefixed without a slash' , async ( ) => {
976
976
977
- const promise = Wreck . request ( 'get' , 'foo' , { baseUrl : 'http://localhost' } ) ;
977
+ const promise = Wreck . request ( 'get' , 'foo' , { baseUrl : 'http://localhost:0 ' } ) ;
978
978
await expect ( promise ) . to . reject ( ) ;
979
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
979
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
980
980
expect ( promise . req . path ) . to . equal ( '/foo' ) ;
981
981
} ) ;
982
982
983
983
it ( 'uses baseUrl option when uri is an empty string' , async ( ) => {
984
984
985
- const promise = Wreck . request ( 'get' , '' , { baseUrl : 'http://localhost' } ) ;
985
+ const promise = Wreck . request ( 'get' , '' , { baseUrl : 'http://localhost:0 ' } ) ;
986
986
await expect ( promise ) . to . reject ( ) ;
987
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
987
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
988
988
expect ( promise . req . path ) . to . equal ( '/' ) ;
989
989
} ) ;
990
990
991
991
it ( 'uses baseUrl option with a path' , async ( ) => {
992
992
993
- const promise = Wreck . request ( 'get' , '/bar' , { baseUrl : 'http://localhost/foo' } ) ;
993
+ const promise = Wreck . request ( 'get' , '/bar' , { baseUrl : 'http://localhost:0 /foo' } ) ;
994
994
await expect ( promise ) . to . reject ( ) ;
995
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
995
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
996
996
expect ( promise . req . path ) . to . equal ( '/foo/bar' ) ;
997
997
} ) ;
998
998
999
999
it ( 'uses baseUrl option with a path and removes extra slashes' , async ( ) => {
1000
1000
1001
- const promise = Wreck . request ( 'get' , '/bar' , { baseUrl : 'http://localhost/foo/' } ) ;
1001
+ const promise = Wreck . request ( 'get' , '/bar' , { baseUrl : 'http://localhost:0 /foo/' } ) ;
1002
1002
await expect ( promise ) . to . reject ( ) ;
1003
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
1003
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
1004
1004
expect ( promise . req . path ) . to . equal ( '/foo/bar' ) ;
1005
1005
} ) ;
1006
1006
1007
1007
it ( 'uses baseUrl option with a url that has a querystring' , async ( ) => {
1008
1008
1009
- const promise = Wreck . request ( 'get' , '/bar?test=hello' , { baseUrl : 'http://localhost/foo' } ) ;
1009
+ const promise = Wreck . request ( 'get' , '/bar?test=hello' , { baseUrl : 'http://localhost:0 /foo' } ) ;
1010
1010
await expect ( promise ) . to . reject ( ) ;
1011
- expect ( promise . req . _headers . host ) . to . equal ( 'localhost' ) ;
1011
+ expect ( promise . req . _headers . host ) . to . equal ( 'localhost:0 ' ) ;
1012
1012
expect ( promise . req . path ) . to . equal ( '/foo/bar?test=hello' ) ;
1013
1013
} ) ;
1014
1014
} ) ;
@@ -1800,7 +1800,7 @@ describe('Events', () => {
1800
1800
once = true ;
1801
1801
} ) ;
1802
1802
1803
- await expect ( wreck . get ( 'http://127.0.0.1 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1803
+ await expect ( wreck . get ( 'http://localhost:0 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1804
1804
expect ( once ) . to . be . true ( ) ;
1805
1805
} ) ;
1806
1806
@@ -1818,8 +1818,8 @@ describe('Events', () => {
1818
1818
const wreck = Wreck . defaults ( { events : true } ) ;
1819
1819
wreck . events . on ( 'response' , handler ) ;
1820
1820
1821
- await expect ( wreck . get ( 'http://127.0.0.1 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1822
- await expect ( wreck . get ( 'http://127.0.0.1 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1821
+ await expect ( wreck . get ( 'http://localhost:0 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1822
+ await expect ( wreck . get ( 'http://localhost:0 ' , { timeout : 10 } ) ) . to . reject ( ) ;
1823
1823
expect ( count ) . to . equal ( 2 ) ;
1824
1824
} ) ;
1825
1825
@@ -2014,6 +2014,12 @@ internals.server = function (handler, socket) {
2014
2014
req . pipe ( res ) ;
2015
2015
} ;
2016
2016
}
2017
+ else if ( handler === 'fail' ) {
2018
+ handler = ( req , res ) => {
2019
+
2020
+ res . socket . destroy ( ) ;
2021
+ } ;
2022
+ }
2017
2023
else if ( handler === 'ok' ) {
2018
2024
handler = ( req , res ) => {
2019
2025
0 commit comments