Skip to content

Do not supply a default content type. #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mullermp opened this issue Jan 22, 2025 · 3 comments · May be fixed by #207
Open

Do not supply a default content type. #205

mullermp opened this issue Jan 22, 2025 · 3 comments · May be fixed by #207

Comments

@mullermp
Copy link

mullermp commented Jan 22, 2025

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
@hsbt
Copy link
Member

hsbt commented Feb 12, 2025

I will ask this to @akr and @nurse at https://bugs.ruby-lang.org/issues/21019

@knu
Copy link
Member

knu commented Feb 13, 2025

We agreed to fix this at the risk of breaking compatibility.

hsbt added a commit that referenced this issue Feb 13, 2025
@hsbt hsbt linked a pull request Feb 13, 2025 that will close this issue
@hsbt
Copy link
Member

hsbt commented Feb 13, 2025

We try to remove default content type for next release. If we faced large issue with this change, we may revert this or apply another approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants