Skip to content

Commit ce0eac1

Browse files
committed
fix issue with use of new URL so it supports relative url's
- motivated by: jupyterhub/configurable-http-proxy#572 (comment)
1 parent 57e3184 commit ce0eac1

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pnpm tsc
5858

5959
and make changes to code under lib/.
6060

61+
Code Style: use prettier with the defaults.
62+
6163
[![Build package and run tests](https://github.com/sagemathinc/http-proxy-3/actions/workflows/test.yml/badge.svg)](https://github.com/sagemathinc/http-proxy-3/actions/workflows/test.yml)
6264

6365
## User's Guide

lib/http-proxy/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
2727
export type ProxyTargetUrl = URL | string;
2828

2929
export interface ServerOptions {
30-
// NOTE: `options.target and `options.forward` cannot be both missing when the
30+
// NOTE: `options.target and `options.forward` cannot be both missing when the
3131
// actually proxying is called. However, they can be missing when creating the
32-
// proxy server in the first place! E.g., you could make a proxy server P with
32+
// proxy server in the first place! E.g., you could make a proxy server P with
3333
// no options, then use P.web(req,res, {target:...}).
3434
// URL string to be parsed with the url module.
3535
target?: ProxyTarget;
@@ -139,7 +139,7 @@ export class ProxyServer extends EventEmitter {
139139

140140
for (const e of ["target", "forward"]) {
141141
if (typeof requestOptions[e] === "string") {
142-
requestOptions[e] = new URL(requestOptions[e]);
142+
requestOptions[e] = new URL(requestOptions[e], "http://dummy.org");
143143
}
144144
}
145145

lib/http-proxy/passes/web-outgoing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export function setRedirectHostRewrite(
5454
proxyRes.headers["location"] &&
5555
redirectRegex.test(`${proxyRes.statusCode}`)
5656
) {
57-
const target = new URL(options.target);
57+
const target = new URL(options.target, "http://dummy.org");
5858
const location = proxyRes.headers["location"];
5959
if (typeof location != "string") {
6060
return;
6161
}
62-
const u = new URL(location);
62+
const u = new URL(location, "http://dummy.org");
6363

6464
// make sure the redirected host matches the target host before rewriting
6565
if (target.host != u.host) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-proxy-3",
3-
"version": "1.20.1",
3+
"version": "1.20.2",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/sagemathinc/http-proxy-3.git"

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ I run these manually before making a release, but not as part of CI. Use
2424
```sh
2525
pnpm test-all
2626
```
27+
2728
to include these tests and also pnpm audit.
2829

2930
## fetch
@@ -48,3 +49,4 @@ These warnings in the test suite are expected, because we're testing ssl using s
4849
(node:52812) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
4950
(Use `node --trace-warnings ...` to show where the warning was created)
5051
```
52+

0 commit comments

Comments
 (0)