ruby / ruby/net-http

Do not supply a default content type.

Open
#205 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
148
Forks
95
Avg merge
10h 54m
Merged PRs (30d)
4

Description

Hello.

I would like to know if you would welcome a change to remove suppy_default_content_type.

Checking RFC for Content-Type: https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.5

   A sender that generates a message containing a payload body SHOULD
   generate a Content-Type header field in that message unless the
   intended media type of the enclosed representation is unknown to the
   sender.  If a Content-Type header field is not present, the recipient
   MAY either assume a media type of "application/octet-stream"
   ([RFC2046], Section 4.5.1) or examine the data to determine its type.

Based on the RFC, I think Net::HTTP behavior is incorrect - assuming a default content type is not correct because the media type is not known unless Net::HTTP reads/inspects the body. The receiver may assume octet-stream unless provided.

This has caused issues with AWS services, where content type may be a modeled API parameter in REST services, like with S3 where you can specify the content type of an object. Currently we work around this with a patch:

Thread.current[:net_http_skip_default_content_type] = true

def self.apply!
  Net::HTTPGenericRequest.prepend(PatchDefaultContentType)
end

module PatchDefaultContentType
  def supply_default_content_type
    return if Thread.current[:net_http_skip_default_content_type]

    super
  end
end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with supply_default_content_type in lib/net/http/generic_request.rb around line 263, then compare its behavior with the RFC 7231 guidance cited in the issue. The change is complete when Net::HTTP no longer supplies an assumed Content-Type for an unknown body, including the AWS-style use case described.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.