Skip to content

Commit 0be5fb9

Browse files
David Molesioquatix
authored andcommitted
Include caller-defined options as MIME headers (#46)
1 parent e045250 commit 0be5fb9

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

lib/parts.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ def initialize(boundary, name, io, headers = {})
6363
end
6464

6565
def build_head(boundary, name, filename, type, content_len, opts = {}, headers = {})
66-
trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
67-
content_disposition = opts["Content-Disposition"] || "form-data"
66+
opts = opts.clone
67+
68+
trans_encoding = opts.delete("Content-Transfer-Encoding") || "binary"
69+
content_disposition = opts.delete("Content-Disposition") || "form-data"
6870

6971
part = ''
7072
part << "--#{boundary}\r\n"
7173
part << "Content-Disposition: #{content_disposition}; name=\"#{name.to_s}\"; filename=\"#{filename}\"\r\n"
7274
part << "Content-Length: #{content_len}\r\n"
73-
if content_id = opts["Content-ID"]
75+
if content_id = opts.delete("Content-ID")
7476
part << "Content-ID: #{content_id}\r\n"
7577
end
7678

@@ -81,6 +83,11 @@ def build_head(boundary, name, filename, type, content_len, opts = {}, headers =
8183
end
8284

8385
part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
86+
87+
opts.each do |k, v|
88+
part << "#{k}: #{v}\r\n"
89+
end
90+
8491
part << "\r\n"
8592
end
8693
end

0 commit comments

Comments
 (0)