Issue with Content Type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Ruby
- Stelle
- 148
- Fork
- 95
- Merge medio
- 10h 54m
- PR unite (30g)
- 4
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci la richiesta POST e ispeziona request.to_hash, quindi leggi net/http/header.rb intorno alla riga 713, dove si verifica il problema segnalato di Content-Type in minuscolo. Traccia l’interazione tra header assignment e content_type; il lavoro è completato quando l’assegnazione dell’header senza distinzione tra maiuscole e minuscole produce un unico Content-Type corretto senza richiedere un secondo setter.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- ruby
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100