Issue with Content Type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 148
- Forks
- 95
- Ø Merge
- 10 Std. 54 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
We've identified an issue in the current release of net-http (0.3.2).
When setting a 'Content-Type' header on a POST request like so:
request['Content-Type'] = 'application/json'
It does set the header, however, it does not recognize that the Content-Type is set correctly and adds an additional header to the request with the default application/x-www-form-urlencoded
This can be seen when calling: request.to_hash.inspect:
{"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "Accept"=>["*/*"], "User-Agent"=>["Ruby"], "Host"=>["api.songstats.com"], "Content-Type"=>["application/json"], "connection"=>["close"], "host"=>["api.songstats.com"], "content-length"=>["290"], "content-type"=>["application/x-www-form-urlencoded"]}
The only way to force the application/json header to go through is to explicitly set it in the request:
request.content_type = 'application/json'
So actually it needs to be set twice in order to fully work:
request['Content-Type'] = 'application/json'
request.content_type = 'application/json'
Also when setting request['content-type'] = 'application/json' in lower case it's throwing the error:
NoMethodError: undefined method `split' for nil:NilClass
from /Users/Oskar/.rbenv/versions/3.2.1/lib/ruby/3.2.0/net/http/header.rb:713:in `main_type'
It would be great if this can be streamlined so that setting the content-type in the headers immediately propagates across the entire request, without the need to set it multiple times or be cautious of case sensitivity. This took us a couple of hours to debug because we were un-aware that it currently sends the same header twice in the same request with different values.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere die POST-Anfrage und untersuche request.to_hash. Lies dann net/http/header.rb um Zeile 713, wo der gemeldete Fehler bei Content-Type in Kleinschreibung auftritt. Verfolge, wie header assignment und content_type interagieren; fertig ist es, wenn die nicht zwischen Groß- und Kleinschreibung unterscheidende header assignment einen einzigen korrekten Content-Type erzeugt, ohne einen zweiten Setter zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- networking
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100