Class: Faraday::Multipart::Middleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday/multipart/middleware.rb

Overview

Middleware for supporting multi-part requests.

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'
DEFAULT_BOUNDARY_PREFIX =
'-----------RubyMultipartPost'

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
15
# File 'lib/faraday/multipart/middleware.rb', line 12

def initialize(app = nil, options = {})
  super(app)
  @options = options
end

Instance Method Details

#call(env) ⇒ Object

Checks for files in the payload, otherwise leaves everything untouched.

Parameters:

  • env (Faraday::Env)


20
21
22
23
24
25
26
27
28
# File 'lib/faraday/multipart/middleware.rb', line 20

def call(env)
  match_content_type(env) do |params|
    env.request.boundary ||= unique_boundary
    env.request_headers[CONTENT_TYPE] +=
      "; boundary=#{env.request.boundary}"
    env.body = create_multipart(env, params)
  end
  @app.call env
end