Sha256: 8102cc3ae6191920f5e194c160d689f0d0df0ee8a028fc7f914f0f7d83673ab2

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module Stash
  module Sword
    module HeaderUtils

      SIMPLE_ZIP                 = 'http://purl.org/net/sword/package/SimpleZip'.freeze
      APPLICATION_ZIP            = 'application/zip'.freeze
      MULTIPART_RELATED_ATOM_XML = 'multipart/related; type="application/atom+xml"'.freeze
      # CONTENT_DISPOSITION        = 'attachment'.freeze
      CONTENT_DISPOSITION        = 'form-data'.freeze

      attr_reader :on_behalf_of

      def create_request_headers(zipfile, slug)
        {
          'Content-Type'        => APPLICATION_ZIP,
          'Content-Disposition' => "#{CONTENT_DISPOSITION}; filename=#{File.basename(zipfile)}",
          'Packaging'           => SIMPLE_ZIP,
          'Content-MD5'         => Digest::MD5.file(zipfile).to_s,
          'On-Behalf-Of'        => on_behalf_of,
          'Slug'                => slug
        }
      end

      def update_request_headers(stream, boundary)
        {
          'Content-Length' => stream.size.to_s,
          'Content-Type'   => "#{MULTIPART_RELATED_ATOM_XML}; boundary=\"#{boundary}\"",
          'On-Behalf-Of'   => on_behalf_of,
          'MIME-Version'   => '1.0'
        }
      end

      def update_mime_headers(zipfile)
        {
          'Content-Type'        => APPLICATION_ZIP,
          'Content-Disposition' => "#{CONTENT_DISPOSITION}; name=\"payload\"; filename=\"#{File.basename(zipfile)}\"",
          'Packaging'           => SIMPLE_ZIP,
          'Content-MD5'         => Digest::MD5.file(zipfile).to_s,
          'MIME-Version'        => '1.0'
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stash-sword-0.1.1 lib/stash/sword/header_utils.rb