-
Notifications
You must be signed in to change notification settings - Fork 237
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
Dont assume JSON accept header when json: true #205
Comments
Yep, I think it does. In the meantime you could try setting the accept header to something different than
An alternative method is to skip setting
|
Oh, sorry. There's no shortcut for the content_type header. The last example should be:
|
Ok, just pushed an update and new version to npm. It should take care of the scenario you describe. :) |
Thanks @tomas! i had already used the first suggestion of setting accept to |
You're welcome @alirussell. Always glad to be of service, specially when I have some spare time, haha. |
https://github.com/tomas/needle/blob/master/lib/needle.js#L355
Is causing issues for me on a specific API, and although its partly the way that I'm using needle and partly the bad implementation of the API, i think that you shouldn't assume that sending a JSON body should result in a JSON response.
In my particular case, the api in question is the Promoter.io add contact API (http://docs.promoter.apiary.io/#reference/contacts/add-a-contactupdate-contact-attributes/add-a-contact/update-contact-attributes). Im POSTing data to this in JSON, and it returns JSON data, but for some reason it doesn't like
accept: application/json
, it only likesaccept: */*
oraccept: application/vnd.promoterio.v1.0
(its weird content type it returns, which is just JSON).The problem I'm having is where I'm using the needle library, its not really possible to modify the
json: true
option to false, and this is forcing theaccept: application/json
header and I'm getting 406 responses.While this is a pretty obscure issue, i don't think you should force the header to
accept: application/json
. The line above checks if accept is non standard (*/*
), but you don't check to see if the default*/*
is actually passed in to the call. If the user specifically sets*/*
as a header, you should probably respect that and not then change it.Make any sense ? :|
The text was updated successfully, but these errors were encountered: