Skip to content

Conversation

@juniorvanin
Copy link

It appears that the Fetch gateway in Mappersmith does not normalize the HTTP method to uppercase, which can cause issues when using HTTP clients like undici that are case-sensitive about method names.

This is a small fix for an issue related to PATCH requests not working properly producing a 400 Bad Request error.

@changeset-bot
Copy link

changeset-bot bot commented Apr 23, 2025

🦋 Changeset detected

Latest commit: 74bc955

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mappersmith Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Nevon
Copy link
Collaborator

Nevon commented Apr 24, 2025

@Nevon Nevon requested a review from klippx April 24, 2025 09:19
Copy link
Collaborator

@klippx klippx left a comment

Choose a reason for hiding this comment

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

Hello, thanks for the contribution! I think it makes sense, but you need to fix tests too, please 🙏


const headers = assign(customHeaders, this.request.headers())
const method = this.shouldEmulateHTTP() ? 'post' : requestMethod
const method = this.shouldEmulateHTTP() ? 'POST' : requestMethod.toUpperCase()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same should be done in two more files, I know this was originally only for Fetch gateway but the way I see it this is not about your specific case and changing Fetch to be different just because of undici:

  • src/gateway/http.ts
  • src/gateway/xhr.ts

'mappersmith': patch
---

Update the performRequest method in the Fetch gateway to normalize the HTTP method to uppercase to mitigate issue with PATCH calls and undici
Copy link
Collaborator

@klippx klippx Apr 24, 2025

Choose a reason for hiding this comment

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

Suggested change
Update the performRequest method in the Fetch gateway to normalize the HTTP method to uppercase to mitigate issue with PATCH calls and undici
Update the `performRequest` method in all gateways to normalize the HTTP method to uppercase. This is to ensure users of mappersmith can continue to use lowercase methods in their manifest and still be compatible with fetch libraries that are equipped with a case sensitive fetch mechanism.

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