Skip to content

Conversation

@zygzagZ
Copy link

@zygzagZ zygzagZ commented Nov 6, 2025

httparty does properly set multipart content type when dealing with files or multipart url bodies. There was no default for urlencoded.

net-http 0.7.0 stops defaulting content type to x-www-form-urlencoded (net-http PR #207, issue #205). HTTParty encodes body with urlencode by default, but does not set content-type. HTTParty's default behavior of urlencoding needs to set content type.

changes in this pr:

  • default content type is set when implicitly encoding body as urlencode, as before with multipart
  • content type default is not used when set or when using custom query_string_normalizer.

If you use custom query_string_normalizer, return content_type as a second argument or pass a Content-Type header

httparty used to properly set multipart content type when dealing with files or multipart url bodies. There was no default for urlencoded.

net-http 0.7.0 stops defaulting content type to x-www-form-urlencoded (net-http PR jnunemaker#207), thus httparty's default behavior of urlencoding needs to set content type.
Content type does not get set when passed or when using custom query_string_normalizer.

If you use custom query_string_normalizer, return content_type as a second argument.
params.respond_to?(:to_hash) && (force_multipart || has_file?(params))
end

def content_type
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it acts as a getter when set, and tries to calc when body is not yet evaluated.

Comment on lines +19 to +24
if multipart?
@content_type = "multipart/form-data; boundary=#{boundary}"
generate_multipart
else
normalize_query_and_set_content_type(params)
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cus generate_multipiart sets @content_type, too

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 this pull request may close these issues.

1 participant