GithubHelp home page GithubHelp logo

Comments (5)

diesieben07 avatar diesieben07 commented on June 29, 2024 1

The XhrBackend behaves differently. It uses HttpHeaders#has, which is a case-insensitive check. Note also that this issue not only applies to Content-Type but also Accept.

See here in XhrBackend:

// Add an Accept header if one isn't present already.
if (!req.headers.has('Accept')) {
xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
}
// Auto-detect the Content-Type header if one isn't present already.
if (!req.headers.has('Content-Type')) {
const detectedType = req.detectContentTypeHeader();
// Sometimes Content-Type detection fails.
if (detectedType !== null) {
xhr.setRequestHeader('Content-Type', detectedType);
}
}

See here for how HttpHeaders#has is case-insensitive:

return this.headers.has(name.toLowerCase());
}

See here for the problematic code in FetchBackend:

// Add an Accept header if one isn't present already.
headers['Accept'] ??= 'application/json, text/plain, */*';
// Auto-detect the Content-Type header if one isn't present already.
if (!headers['Content-Type']) {
const detectedType = req.detectContentTypeHeader();
// Sometimes Content-Type detection fails.
if (detectedType !== null) {
headers['Content-Type'] = detectedType;
}
}

from angular.

diesieben07 avatar diesieben07 commented on June 29, 2024 1

@wduminy The reason that binary data doesn't exhibit the same behavior is that Angular doesn't have a content type to infer.

from angular.

JeanMeche avatar JeanMeche commented on June 29, 2024

It looks like the behavior is consistent with how the XhrBackend is behaving. Although I agree headers should be case insensitive.

I'm wondering how breaking would it be to make that change.

from angular.

JeanMeche avatar JeanMeche commented on June 29, 2024

Right, I must have missed something in my tests.

#56539 will provide the fix for this. Thank you for the investigation.

from angular.

wduminy avatar wduminy commented on June 29, 2024

@JeanMeche Quick update: In the code I reported above I used JSON data; but when I used binary data -- a more realistic use case -- the problem did not occur -- i.e. application/json was not inserted.

So case sensitivity might be a problem; but the use-case here is certainly "contrived by accident".

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.