Sha256: 5b781ad5faad72b2e81da94f8816cbe0bedb1e195e61eba5e6ecf0e6d4436fa4

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

# This is really shitty and no one should ever monkey patch, but the Apple News API
# requires that the size of the form part should be specified in the Content-Disposition
# header, and not with the Content-Length header. I'm not sure if size is even a valid param
# in the Content-Disposition header, but here we are.
module Parts
  class FilePart
    def build_head(boundary, name, filename, type, content_len, opts = {}, headers = {})
      trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
      content_disposition = opts["Content-Disposition"] || "form-data"

      part = ''
      part << "--#{boundary}\r\n"
      part << "Content-Disposition: #{content_disposition}; name=#{name}; filename=\"#{filename}\"; size=#{content_len}\r\n"
      part << "Content-Length: #{content_len}\r\n"
      if content_id = opts["Content-ID"]
        part << "Content-ID: #{content_id}\r\n"
      end

      if headers["Content-Type"] != nil
        part <<  "Content-Type: " + headers["Content-Type"] + "\r\n"
      else
        part << "Content-Type: #{type}\r\n"
      end

      part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
      part << "\r\n"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
apple-news-0.5.1 lib/apple-news/multipart_post_patch.rb
apple-news-0.5.0 lib/apple-news/multipart_post_patch.rb
apple-news-0.4.2 lib/apple-news/multipart_post_patch.rb
apple-news-0.4.1 lib/apple-news/multipart_post_patch.rb
apple-news-0.4.0 lib/apple-news/multipart_post_patch.rb
apple-news-0.3.1 lib/apple-news/multipart_post_patch.rb
apple-news-0.3.0 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.5 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.4 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.3 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.2 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.1 lib/apple-news/multipart_post_patch.rb
apple-news-0.2.0 lib/apple-news/multipart_post_patch.rb
apple-news-0.1.1 lib/apple-news/multipart_post_patch.rb
apple-news-0.1.0 lib/apple-news/multipart_post_patch.rb