File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
src/utils/http-client/get-modules
tests/src/utils/http-client Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,13 @@ function get0(
3939 res . statusCode < 400 &&
4040 redirectCount < 3 // max redirect
4141 ) {
42- const redirectUrl = res . headers . location ! ;
43- resolve ( get0 ( redirectUrl , options , redirectCount + 1 ) ) ;
42+ const location = res . headers . location ! ;
43+ try {
44+ const redirectUrl = new URL ( location , url ) . toString ( ) ;
45+ resolve ( get0 ( redirectUrl , options , redirectCount + 1 ) ) ;
46+ } catch ( e ) {
47+ reject ( e ) ;
48+ }
4449 return ;
4550 }
4651 resolve ( result ) ;
Original file line number Diff line number Diff line change @@ -22,4 +22,22 @@ describe("HTTP GET.", () => {
2222 "eslint-plugin-json-schema-validator"
2323 ) ;
2424 } ) ;
25+ it ( "Should to receive a request with a redirect." , async ( ) => {
26+ const res = await get (
27+ "https://unpkg.com/eslint-plugin-json-schema-validator/package.json"
28+ ) ;
29+ assert . deepStrictEqual (
30+ JSON . parse ( res ) . name ,
31+ "eslint-plugin-json-schema-validator"
32+ ) ;
33+ } ) ;
34+ it ( "Should to receive a request with a redirect (2)." , async ( ) => {
35+ const res = await get (
36+ "https://raw.github.com/ota-meshi/eslint-plugin-json-schema-validator/main/package.json"
37+ ) ;
38+ assert . deepStrictEqual (
39+ JSON . parse ( res ) . name ,
40+ "eslint-plugin-json-schema-validator"
41+ ) ;
42+ } ) ;
2543} ) ;
You can’t perform that action at this time.
0 commit comments