Skip to content

Uppercase the http method #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
2 changes: 1 addition & 1 deletion src/http-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class HttpContext {
}

const { headers, header, url: rawUrl, method: m } = req.json();
const method = m ?? 'GET';
const method = m?.toUpperCase() ?? 'GET';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed there are explicit conditional checks for uppercase below. is there somewhere else this could be getting set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope – I think this code used to assume that the pdk will always call with uppercased HTTP verbs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, TIL ?. earlier in the chain cascades to the ()! I would've thought m?.toUpperCase?.() would be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it works for methods too? at least i've been doing this in other places. the compiler didn't complain but also i think it's an any. This does seem to work though:

function z(s?: string | null) {
  console.log(s?.toUpperCase() || "GET")
}

z()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

becomes:

"use strict";
function z(s) {
    console.log((s === null || s === void 0 ? void 0 : s.toUpperCase()) || "GET");
}
z();

const url = new URL(rawUrl);

const isAllowed = this.allowedHosts.some((allowedHost) => {
Expand Down