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

handle default Content-Type being set in default Response instances #1049

Open
thescientist13 opened this issue Feb 5, 2023 · 0 comments
Open
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) good first issue Good for newcomers
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Feb 5, 2023

Type of Change

Enhancement

Summary

As part of #948 , one thing that was observed was that in NodeJS at least, a Response object by default will have a default Content-Type of text/plain;charset=UTF-8. This means when running mergeResponse in resource-utils.js this will overwrite any incoming Content-Type set by a plugin.

Details

To work around this, we have to do something like below, so it would be nice to see if there is a better way to handle this, in the off chance someone actually wants to return this specific value.

function mergeResponse(destination, source) {
  const headers = destination.headers || new Headers();

  source.headers.forEach((value, key) => {
    const isDefaultHeader = key.toLowerCase() === 'content-type' && value === 'text/plain;charset=UTF-8';

    if (!isDefaultHeader) {
      headers.set(key, value);
    }
  });

  return new Response(source.body, {
    headers
  });
}

Does casing matter; `Content-Type' vs 'content-type'? 🤔

@thescientist13 thescientist13 added the enhancement Improve something existing (e.g. no docs, new APIs, etc) label Feb 5, 2023
@thescientist13 thescientist13 added this to the 1.0 milestone Feb 5, 2023
@thescientist13 thescientist13 added the good first issue Good for newcomers label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) good first issue Good for newcomers
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant