Class: Psc::Faraday::StringIsXml

Inherits:
Object
  • Object
show all
Defined in:
lib/psc/faraday/string_is_xml.rb

Overview

Middleware which sets the request content type to text/xml if the provided body is a String and the content type isn't already set.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ StringIsXml

Returns a new instance of StringIsXml.



10
11
12
# File 'lib/psc/faraday/string_is_xml.rb', line 10

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Sets the content type request header if appropriate



16
17
18
19
20
21
22
# File 'lib/psc/faraday/string_is_xml.rb', line 16

def call(env)
  if String === env[:body]
    env[:request_headers]['Content-Type'] ||= 'text/xml'
  end

  @app.call(env)
end