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

Content-Type response header detection should not be case sensitive #314

Closed
vch-7 opened this issue Jan 28, 2022 · 0 comments · Fixed by #315
Closed

Content-Type response header detection should not be case sensitive #314

vch-7 opened this issue Jan 28, 2022 · 0 comments · Fixed by #315

Comments

@vch-7
Copy link
Contributor

vch-7 commented Jan 28, 2022

Header field names and MIME type detection should not be case sensitive.
The getResult function checks for the existence of the Content-Type response header. This check should be able to accept a case-insensitive header field name and value (for e.g. content-type: application/json)

function getResult(response: Dom.Response): Promise<any> {
  const contentType = response.headers.get('Content-Type')
  if (contentType && contentType.startsWith('application/json')) {
    return response.json()
  } else {
    return response.text()
  }
}

The primary use case for this would be when the default fetch config in the GraphQLClient instance is overridden with say, an Axios wrapper, where the Response Header object does not implement a case-insensitive get method by default.

References:
https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2
https://www.rfc-editor.org/rfc/rfc6838.html#section-4.2

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 a pull request may close this issue.

1 participant