Issue with Content Type

オープン
#148 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
ruby
領域
networking

調査の方向性

POST リクエストを再現して request.to_hash を調べ、次に net/http/header.rb の 713 行目付近を読み、報告された小文字の Content-Type の失敗が発生する箇所を確認します。header assignment と content_type がどのように相互作用するかを追跡します。完了の条件は、大文字と小文字を区別しない header assignment によって、2 回目の setter を必要とせず、正しい Content-Type が 1 つ生成されることです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Ruby
スター
148
フォーク
95
平均マージ
10時間 54分
マージ済み PR(30日)
4

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/net-http のほかの issue

ruby/net-http の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。