Skip to content

Commit

Permalink
[node] Handle multi-protocol in Edge Functions (#9502)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Barber <chris.barber@vercel.com>
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
fix #9501
  • Loading branch information
PonomareVlad committed Mar 16, 2023
1 parent e210977 commit af7b34a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/node/src/edge-functions/edge-handler-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* global addEventListener */

function buildUrl(requestDetails) {
let proto = requestDetails.headers['x-forwarded-proto'];
let proto = requestDetails.headers['x-forwarded-proto'].split(/\b/).shift(); // handling multi-protocol like https,http://...
let host = requestDetails.headers['x-forwarded-host'];
let path = requestDetails.url;
return `${proto}://${host}${path}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ describe('edge-handler-template', () => {
});
expect(url).toBe('https://somewhere.com/api/add');
});

test('works with multi proto', async () => {
const url = buildUrl({
url: '/api/add',
headers: {
'x-forwarded-proto': 'https,http',
'x-forwarded-host': 'somewhere.com',
},
});
expect(url).toBe('https://somewhere.com/api/add');
});
});

describe('respond()', () => {
Expand Down

0 comments on commit af7b34a

Please sign in to comment.