Skip to content

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.


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!


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.

3 participants