Skip to content

Commit 642d274

Browse files
fix: default content-type for text in multi-part formdata uploads should be text/plain
1 parent 62260a5 commit 642d274

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/onebusaway_sdk/internal/util.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class << self
497497
# @param closing [Array<Proc>]
498498
# @param content_type [String, nil]
499499
private def write_multipart_content(y, val:, closing:, content_type: nil)
500-
content_type ||= "application/octet-stream"
500+
content_line = "Content-Type: %s\r\n\r\n"
501501

502502
case val
503503
in OnebusawaySDK::FilePart
@@ -508,24 +508,21 @@ class << self
508508
content_type: val.content_type
509509
)
510510
in Pathname
511-
y << "Content-Type: #{content_type}\r\n\r\n"
511+
y << format(content_line, content_type || "application/octet-stream")
512512
io = val.open(binmode: true)
513513
closing << io.method(:close)
514514
IO.copy_stream(io, y)
515515
in IO
516-
y << "Content-Type: #{content_type}\r\n\r\n"
516+
y << format(content_line, content_type || "application/octet-stream")
517517
IO.copy_stream(val, y)
518518
in StringIO
519-
y << "Content-Type: #{content_type}\r\n\r\n"
519+
y << format(content_line, content_type || "application/octet-stream")
520520
y << val.string
521-
in String
522-
y << "Content-Type: #{content_type}\r\n\r\n"
523-
y << val.to_s
524521
in -> { primitive?(_1) }
525-
y << "Content-Type: text/plain\r\n\r\n"
522+
y << format(content_line, content_type || "text/plain")
526523
y << val.to_s
527524
else
528-
y << "Content-Type: application/json\r\n\r\n"
525+
y << format(content_line, content_type || "application/json")
529526
y << JSON.generate(val)
530527
end
531528
y << "\r\n"
@@ -563,6 +560,8 @@ class << self
563560

564561
# @api private
565562
#
563+
# https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#special-considerations-for-multipart-content
564+
#
566565
# @param body [Object]
567566
#
568567
# @return [Array(String, Enumerable<String>)]

rbi/onebusaway_sdk/internal/util.rbi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ module OnebusawaySDK
332332
end
333333

334334
# @api private
335+
#
336+
# https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#special-considerations-for-multipart-content
335337
sig do
336338
params(body: T.anything).returns([String, T::Enumerable[String]])
337339
end

0 commit comments

Comments
 (0)