Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP requests have the wrong Content-Type header #164

Open
doga opened this issue Feb 19, 2016 · 3 comments
Open

HTTP requests have the wrong Content-Type header #164

doga opened this issue Feb 19, 2016 · 3 comments

Comments

@doga
Copy link

doga commented Feb 19, 2016

Hello,

I have noticed that JsonApiClient::Resource sends HTTP requests with a "Content-Type: application/json" header. Here is what needs fixing:

This is a library that I plan on using in production if I can, so congrats.

@JohnSmall
Copy link

I have a similar problem when accessing an endpoint implemented in another language where the developer had to roll their own implementation, and made some mistakes. I need to add a media header to all GET requests, and the content type has to be the standard media type for JSON API.

But I can't find where I make the change. I suspect it's in the middleware.

@natemacinnes
Copy link
Contributor

natemacinnes commented Aug 22, 2016

@JohnSmall You are correct in your assumption that it requires you to add it in the middleware.
I ran into a similar issue and was able to override the headers by adding my own middleware class like so:

module Api
    class Request < Faraday::Middleware
      def call(environment)
        environment[:request_headers]["Content-Type"]   = "application/vnd.api+json,application/vnd.api+json;com.api.version=#{Base.version}"
        environment[:request_headers]["Accept"]         = "application/vnd.api+json,application/vnd.api+json;com.api.version=#{Base.version}"
        environment[:request_headers]["User-Agent"]     = "Api Ruby Client v0.1.0"
        environment[:request_headers]["Authorization"]  = "Token token=#{Base.access_token}"
        @app.call(environment)
      end
    end
end

As per the example in the README

@JohnSmall
Copy link

Thanks for the advice

Any idea how I would modify the middleware to deal with SSL client certificates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants