Skip to content

Commit 16ccd85

Browse files
committed
Fix fly proxy proto config
1 parent 4ed261d commit 16ccd85

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

fly.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ primary_region = 'cdg'
2323

2424
[[services]]
2525
protocol = "tcp"
26-
internal = 8080
27-
28-
[services.proxy_proto_options]
29-
version = "v1"
26+
internal_port = 8080
3027

3128
[[services.ports]]
3229
port = "80"
30+
handlers = ["proxy_proto"]
3331
[[services.ports]]
3432
port = "443"
33+
handlers = ["proxy_proto"]
3534
[[services.ports]]
3635
start_port = 8000
3736
end_port = 10000
37+
handlers = ["proxy_proto"]
3838

3939
# Continually check /echo can return a valid HTTPS response
4040
[[services.http_checks]]

test/ip.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,39 @@ describe("IP endpoint", () => {
223223
expect(body.origin).to.equal('198.18.0.42');
224224
});
225225

226+
it("extracts origin from PROXY v1 header with TLS + HTTP/2", async () => {
227+
const socket = await createProxySocket(proxyServerPort,
228+
buildProxyV1Header('203.0.113.99', '10.0.0.1', 22222, 443)
229+
);
230+
231+
// Wait for server to process PROXY header before TLS handshake
232+
await new Promise(resolve => setTimeout(resolve, 10));
233+
234+
const tlsSocket = tls.connect({
235+
socket,
236+
servername: 'localhost',
237+
rejectUnauthorized: false,
238+
ALPNProtocols: ['h2']
239+
});
240+
await new Promise<void>((resolve) => tlsSocket.on('secureConnect', resolve));
241+
242+
expect(tlsSocket.alpnProtocol).to.equal('h2');
243+
244+
const client = http2.connect('https://localhost', {
245+
createConnection: () => tlsSocket as any
246+
});
247+
248+
const request = client.request({
249+
':path': '/ip',
250+
':method': 'GET'
251+
});
252+
253+
const body: any = await streamConsumers.json(request);
254+
client.close();
255+
256+
expect(body.origin).to.equal('203.0.113.99');
257+
});
258+
226259
it("handles malformed PROXY v1 with invalid port gracefully", async () => {
227260
const socket = await createProxySocket(proxyServerPort,
228261
Buffer.from('PROXY TCP4 1.2.3.4 5.6.7.8 99999 80\r\n')

0 commit comments

Comments
 (0)