-
Notifications
You must be signed in to change notification settings - Fork 299
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
[fix] Allowing raw request body when Content-Type is already specified #60
Conversation
Would you mind adding a test for this? |
@sferik done. apologies for not including that from the get go. |
No need to apologize. Thanks for the patch! |
[fix] Allowing raw request body when Content-Type is already specified
Just my own guilt ;-) Thanks Erik. |
@sferik got a few people asking when this fix will be released. Ads API in particular has a new feature launching this week which twurl won't work with unless this fix is present. Do you have an ETA on when we'll be cutting a new gem? I hate to ask for a release just for this, but I also don't see much else in motion on here at the moment. |
@sferik Ping. |
Hey. Thanks for the ping. I was on vacation last week. I’ll try to get to this later today. I’ll also add you as a gem owner so you can push releases yourself in the future. |
Thanks a bunch @sferik! |
Currently, when you use the
-d
option twurl callsrequest.set_form_data
which URL encodes the request body and overrides any previously setContent-Type
value by forcibly setting it toapplication/x-www-form-urlencoded
.https://github.com/twitter/twurl/blob/master/lib/twurl/oauth_client.rb#L112
Example without Modification (Unexpected Behavior):
This behavior prevents users from ever being able to send a request with
Content-Type: application/json
and a JSON payload in the request body.The change I'm making here is simple, non-breaking and preserves the default behavior while allowing the expected behavior you'd see in curl for the scenario described. If the request has
Content-Type
set to any value, we setrequest.body
to the raw value ofoptions.data
and leave the content header untouched.Example with Modification (Expected Behavior):