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

Fix: Duplicate Content-Type header when Content-Type header is capitalized. #154

Conversation

JustinSomers
Copy link
Contributor

When a Content-Type header exists in a incomingRequest object that is passed into the fetch function, we will receive a duplicate lowercase content-type header.

Here is where the error occurs in the source code

    if (this.shouldJSONSerializeBody(augmentedRequest.body)) {
      augmentedRequest.body = JSON.stringify(augmentedRequest.body);
      // If Content-Type header has not been previously set, set to application/json
      if (!augmentedRequest.headers) {
        augmentedRequest.headers = { 'content-type': 'application/json' };
      } else if (!augmentedRequest.headers['content-type']) {
        augmentedRequest.headers['content-type'] = 'application/json';
      }

What my proposed change does is it checks for the capitalized Content-Type header, if it exists we create a lowercase content-type header and delete the capitalized one.

Alternatively, we could just change the above if statement to:

else if (!augmentedRequest.headers['content-type'] && !augmentedRequest.headers['Content-Type']) {

@apollo-cla
Copy link

@JustinSomers: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 1, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

src/RESTDataSource.ts Outdated Show resolved Hide resolved
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

Very minor nitpicks, overall looks good to me!

Can you please add a patch changeset (via the npx changeset command) with a brief description of the user-facing impact this change has? (what does it fix)

Thank you!

src/__tests__/RESTDataSource.test.ts Outdated Show resolved Hide resolved
src/__tests__/RESTDataSource.test.ts Outdated Show resolved Hide resolved
src/__tests__/RESTDataSource.test.ts Outdated Show resolved Hide resolved
src/__tests__/RESTDataSource.test.ts Outdated Show resolved Hide resolved
src/RESTDataSource.ts Outdated Show resolved Hide resolved
@trevor-scheer
Copy link
Member

I'm usually able to trigger a Circle CI run on forks by pushing an empty commit, but that doesn't seem to be working. I opened a separate branch (which I'll be deleting) just to see CI pass.

@trevor-scheer trevor-scheer merged commit bb0cff0 into apollographql:main Feb 6, 2023
@github-actions github-actions bot mentioned this pull request Feb 6, 2023
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.

5 participants