Skip to content

Commit bbc4658

Browse files
committed
Add trailing clrf when building header for non-file parts.
When building a `StreamingMultipartBody`, the following example shows the header for the `first_name` part should be followed by a clrf before the part's content starts. ==== Before ==== --test-boundary-123 Content-Disposition: form-data; name="avatar"; filename="tiny.gif" Content-Type: image/gif GIF89a,; --test-boundary-123 Content-Disposition: form-data; name="first_name" John --test-boundary-123 ==== After ==== --test-boundary-123 Content-Disposition: form-data; name="avatar"; filename="tiny.gif" Content-Type: image/gif GIF89a,; --test-boundary-123 Content-Disposition: form-data; name="first_name" John --test-boundary-123
1 parent 55ec76e commit bbc4658

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/httparty/request/streaming_multipart_body.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def build_part_header(key, value, is_file)
135135
header << %(; filename="#{file_name(value).gsub(/["\r\n]/, replacement_table)}").b
136136
header << NEWLINE.b
137137
header << "Content-Type: #{content_type(value)}#{NEWLINE}".b
138+
else
139+
header << NEWLINE.b
138140
end
139141
header << NEWLINE.b
140142
header

spec/httparty/request_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@
282282
allow(HTTParty::Request::MultipartBoundary).to receive(:generate).and_return('test-boundary-123')
283283

284284
# Get streaming content
285-
request1 = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', body: { avatar: file })
285+
request1 = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', body: { avatar: file, first_name: "John" })
286286
request1.send(:setup_raw_request)
287287
streaming_content = request1.instance_variable_get(:@raw_request).body_stream.read
288288

289289
file.rewind
290290

291291
# Get non-streaming content
292-
request2 = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', body: { avatar: file }, stream_body: false)
292+
request2 = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', body: { avatar: file, first_name: "John" }, stream_body: false)
293293
request2.send(:setup_raw_request)
294294
non_streaming_content = request2.instance_variable_get(:@raw_request).body
295295

0 commit comments

Comments
 (0)