Skip to content
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

Uppercase the http method #112

Merged
merged 1 commit into from
Jan 29, 2025
Merged

Uppercase the http method #112

merged 1 commit into from
Jan 29, 2025

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Jan 29, 2025

Unclear exactly if this is a problem here or if this is the right spot, but had an issue where googleapis.com didn't accept a lowercase http method from the client. gonna make sure the same is in go and rust.

@@ -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

@chrisdickinson chrisdickinson left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -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

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();

@bhelx bhelx merged commit ae88c5d into main Jan 29, 2025
5 checks passed
@bhelx bhelx deleted the uppercase-the-http-method branch January 29, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants