I am using faraday
to handle some requests to an internal API. The API endpoints use a CSRF token, so I am also using faraday-cookie_jar
.
For a couple of the API endpoints, they require a :multipart
request. Others do not.
Question
Is there any way to utilize the same Connection
object, but switch whether or not you are doing a :multipart
or a :url_encoded
request?
Currently, I have to use two connections depending on which type of request I'm making. It does not seem you can change a connection's request method after it has done at least 1 request.
@connection = Faraday.new(url: 'http://localhost:3000') do |faraday|
faraday.request :url_encoded
faraday.use :cookie_jar
faraday.adapter Faraday.default_adapter
end
@connection.get '/something'
# try to change to :multipart
@connection.request :multipart # => Faraday::RackBuilder::StackLocked: can't modify middleware stack after making a request
It doesn't seem to allow you to switch after you've made a request. I know that you can modify the request a bit for each request itself by passing a block, but I can't seem to find where to modify to switch to :multipart
in it.
Thanks in advance.