Class: Faraday::EncodeXML::Middleware

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

Overview

Request middleware that encodes the body as XML.

Processes only requests with matching Content-type or those without a type. If a request doesn’t have a type but has a body, it sets the Content-type to XML MIME-type.

Doesn’t try to encode bodies that already are in string form.

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'
MIME_TYPE =
'application/xml'

Instance Method Summary collapse

Instance Method Details

#on_request(env) ⇒ Object

This method will be called when the request is being prepared. You can alter it as you like, accessing things like request_body, request_headers, and more. Refer to Faraday::Env for a list of accessible fields: github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb

Parameters:

  • env (Faraday::Env)

    the environment of the request being processed



25
26
27
28
29
# File 'lib/faraday/encode_xml/middleware.rb', line 25

def on_request(env)
  match_content_type(env) do |data|
    env[:body] = encode data
  end
end