Issue with Content Type

Abierto
#148 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
ruby
Área
networking

Línea de trabajo

Reproduce la solicitud POST e inspecciona request.to_hash; después, lee net/http/header.rb alrededor de la línea 713, donde se produce el error reportado de Content-Type en minúsculas. Rastrea cómo interactúan header assignment y content_type; estará terminado cuando la asignación de encabezados sin distinción entre mayúsculas y minúsculas produzca un único Content-Type correcto sin requerir un segundo setter.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Ruby
Estrellas
148
Forks
95
Merge medio
10 h 54 min
PR fusionados (30 d)
4

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ruby/net-http

Todos los issues de ruby/net-http

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.