Skip to content
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

Add the ability to set Content-ID header for ParamPart #62

Merged
merged 2 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/parts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ParamPart
# @param boundary [String]
# @param name [#to_s]
# @param value [String]
# @param headers [Hash] Content-Type is used, if present.
# @param headers [Hash] Content-Type and Content-ID are used, if present.
def initialize(boundary, name, value, headers = {})
@part = build_part(boundary, name, value, headers)
@io = StringIO.new(@part)
Expand All @@ -52,6 +52,7 @@ def length
def build_part(boundary, name, value, headers = {})
part = ''
part << "--#{boundary}\r\n"
part << "Content-ID: #{headers["Content-ID"]}\r\n" if headers["Content-ID"]
part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
part << "\r\n"
Expand Down
5 changes: 5 additions & 0 deletions spec/parts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ def content_type; 'application/data'; end
it "test_correct_length" do
assert_part_length @part
end

it "test_content_id" do
part = Parts::ParamPart.new("boundary", "with_content_id", "foobar", "Content-ID" => "id")
expect(part.to_io.read).to match(/Content-ID: id/)
end
end