Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ export function makeHttpRequestData(
responseSize,
latency;
// Format request properties
if (req.url) {
requestUrl = req.url;
const url = new URL(requestUrl);
protocol = url.protocol;
}
if (req.url) requestUrl = req.url;
// OriginalURL overwrites inferred url
if ('originalUrl' in req && req.originalUrl) {
requestUrl = req.originalUrl;
const url = new URL(requestUrl);
protocol = url.protocol;
if ('originalUrl' in req && req.originalUrl) requestUrl = req.originalUrl;
// Format protocol from valid URL
if (requestUrl) {
try {
const url = new URL(requestUrl);
protocol = url.protocol;
} catch (e) {
// Library should not panic
}
}
req.method ? (requestMethod = req.method) : null;
if (req.headers && req.headers['user-agent']) {
Expand Down
10 changes: 10 additions & 0 deletions test/http-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ describe('http-request', () => {
assert.strictEqual(cloudReq.requestUrl, 'http://google.com/');
assert.strictEqual(cloudReq.requestMethod, 'GET');
});
it('should not panic on invalid URL', () => {
const req = {
method: 'GET',
originalUrl: 'invalid/url/',
} as ServerRequest;
const cloudReq = makeHttpRequestData(req);
assert.strictEqual(cloudReq.protocol, undefined);
assert.strictEqual(cloudReq.requestUrl, 'invalid/url/');
assert.strictEqual(cloudReq.requestMethod, 'GET');
});
it('should infer as many request values as possible', () => {
const req = {
method: 'GET',
Expand Down