Content-type Header Not Handled Correctly for JSON and Form Data with Charset Information
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 55/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- javascript, node.js
- Domaine
- backend
Piste de recherche
Commencez dans examples/middleware/bodyDecoder-middleware.js aux lignes 47-53 et reproduisez la requête avec Content-type: application/json; charset=utf-8 ou la forme équivalente de l’en-tête form-data. Vérifiez que les deux types de contenu paramétrés sont correctement décodés et sérialisés, tandis que les types de contenu purs existants continuent de fonctionner.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
In the file bodyDecoder-middleware.js, lines 47-53, the server incorrectly handles Content-type: application/json; charset=utf-8 headers and similarly formatted headers for form data (application/x-www-form-urlencoded). The existing code uses strict string comparison, causing issues when the Content-type header contains additional properties like charset.
Existing Code
// bodyDecoder-middleware.js, lines 47-53
if (contentType === 'application/json') {
bodyData = JSON.stringify(req.body);
}
if (contentType === 'application/x-www-form-urlencoded') {
bodyData = queryString.stringify(req.body);
}
This code only works for requests that send a pure Content-type: application/json or Content-type: application/x-www-form-urlencoded without any additional properties like charset.
Expected behavior
The code should be able to handle Content-type headers with additional parameters.
Standard Practice According to MDN
According to MDN's documentation on Content-Type, the header can contain additional parameters (like charset), separated by a semicolon. Therefore, using startsWith would align better with this standard practice.
Solution
A possible solution is to change the string comparison to check if the Content-type starts with the desired value. Below is the proposed change:
if (contentType.startsWith('application/json')) {
bodyData = JSON.stringify(req.body);
}
if (contentType.startsWith('application/x-www-form-urlencoded')) {
bodyData = queryString.stringify(req.body);
}
Steps to Reproduce
- Send a POST request with a
Content-type: application/json; charset=utf-8header and JSON payload. - Observe that the existing code does not handle the body as expected.
Thank you for taking the time to look into this issue.
- Langage dominant
- JavaScript
- Étoiles
- 14.1k
- Forks
- 2k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de http-party/node-http-proxy
-
util._extend() is depracatoryOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
http-party/node-http-proxy#1719 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
http-party/node-http-proxy#1721 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 55/100
http-party/node-http-proxy#1715 · 1 commentaire · 5 réactions ·
-
Is this library is dead?Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 15/100
http-party/node-http-proxy#1711 · 2 commentaires ·
-
HTTP3 + QUIC support?Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
http-party/node-http-proxy#1710 · 5 réactions ·
Toutes les issues de http-party/node-http-proxy
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
ImranR98/apps.obtainium.imranr.dev#2000 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
routing: the tray panel's stage stands still with motion reduced while a request is in flightOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
microsoft/monaco-editor#5577 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
obsidianmd/obsidian-help#1169 ·
Les mainteneurs répondent en général sous 2 jours
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish stepPeut-être pris @albertteoh l’a pris aujourd’hui. Ouvertedocumentation
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
jaegertracing/jaeger-ui#4739 ·
Les mainteneurs répondent en général sous 1 jour