Skip to content

Commit 4ed7b3a

Browse files
committed
Include query parameters when proxying
1 parent 02e3366 commit 4ed7b3a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

doc/FAQ.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ You can use [Let's Encrypt](https://letsencrypt.org/) to get an SSL certificate
6666
for free.
6767

6868
## How do I access web services?
69+
6970
code-server is capable of proxying to any port using either a subdomain or a
7071
subpath.
7172

7273
### Sub-domains
74+
7375
Set up a wildcard certificate for your domain and a wildcard DNS entry (or you
7476
can configure each subdomain individually for the ports you expect to use).
7577

@@ -83,6 +85,7 @@ Now you can browse to `<port>.coder.com`. Note that this uses the host header so
8385
ensure your reverse proxy forwards that information if you are using one.
8486

8587
### Sub-paths
88+
8689
Just browse to `/proxy/<port>/`.
8790

8891
## x86 releases?

src/node/app/proxy.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { logger } from "@coder/logger"
22
import * as http from "http"
33
import proxy from "http-proxy"
44
import * as net from "net"
5+
import * as querystring from "querystring"
56
import { HttpCode, HttpError } from "../../common/http"
67
import { HttpProvider, HttpProviderOptions, HttpProxyProvider, HttpResponse, Route } from "../http"
78

@@ -47,7 +48,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
4748
}
4849
}
4950

50-
const payload = this.doProxy(route.requestPath, request, response, base)
51+
const payload = this.doProxy(route.requestPath, route.query, request, response, base)
5152
if (payload) {
5253
return payload
5354
}
@@ -62,7 +63,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
6263
head: Buffer,
6364
): Promise<void> {
6465
this.ensureAuthenticated(request)
65-
this.doProxy(route.requestPath, request, socket, head, route.base.replace(/^\//, ""))
66+
this.doProxy(route.requestPath, route.query, request, socket, head, route.base.replace(/^\//, ""))
6667
}
6768

6869
public getCookieDomain(host: string): string {
@@ -83,7 +84,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
8384
response: http.ServerResponse,
8485
): HttpResponse | undefined {
8586
const port = this.getPort(request)
86-
return port ? this.doProxy(route.fullPath, request, response, port) : undefined
87+
return port ? this.doProxy(route.fullPath, route.query, request, response, port) : undefined
8788
}
8889

8990
public maybeProxyWebSocket(
@@ -93,7 +94,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
9394
head: Buffer,
9495
): HttpResponse | undefined {
9596
const port = this.getPort(request)
96-
return port ? this.doProxy(route.fullPath, request, socket, head, port) : undefined
97+
return port ? this.doProxy(route.fullPath, route.query, request, socket, head, port) : undefined
9798
}
9899

99100
private getPort(request: http.IncomingMessage): string | undefined {
@@ -121,19 +122,22 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
121122

122123
private doProxy(
123124
path: string,
125+
query: querystring.ParsedUrlQuery,
124126
request: http.IncomingMessage,
125127
response: http.ServerResponse,
126128
portStr: string,
127129
): HttpResponse
128130
private doProxy(
129131
path: string,
132+
query: querystring.ParsedUrlQuery,
130133
request: http.IncomingMessage,
131134
socket: net.Socket,
132135
head: Buffer,
133136
portStr: string,
134137
): HttpResponse
135138
private doProxy(
136139
path: string,
140+
query: querystring.ParsedUrlQuery,
137141
request: http.IncomingMessage,
138142
responseOrSocket: http.ServerResponse | net.Socket,
139143
headOrPortStr: Buffer | string,
@@ -159,7 +163,9 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
159163
autoRewrite: true,
160164
changeOrigin: true,
161165
ignorePath: true,
162-
target: `http://127.0.0.1:${port}${path}`,
166+
target: `http://127.0.0.1:${port}${path}${
167+
Object.keys(query).length > 0 ? `?${querystring.stringify(query)}` : ""
168+
}`,
163169
}
164170

165171
if (responseOrSocket instanceof net.Socket) {

0 commit comments

Comments
 (0)