question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content-Type Override

See original GitHub issue

From this bit of code in _putorPost() function in oauth.js (line 496)

if ( typeof post_body != "string" && !Buffer.isBuffer(post_body) ) { post_content_type= "application/x-www-form-urlencoded" extra_params= post_body; post_body= null; }

With the new Twitter DM API I need to be able to set the Content Type to JSON when the post-body is JSON https://dev.twitter.com/rest/reference/post/direct_messages/events/new

So currently my post function looks like this : oauth.post( ‘https://api.twitter.com//1.1/direct_messages/events/new.json’, access_token, access_token_secret, {“event”: {“type”: “message_create”, “message_create”: {“target”: {“recipient_id”: “4534871”}, “message_data”: {“text”: “Hello World!”}}}}, “application/json”, function(e, data ) { } );

But as post-content-type gets overridden to “application/x-www-form-urlencoded”, I get an error. Could this please be updated so you can specify the content type?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
rausankacommented, Jul 26, 2017

A minimal change (which I think is less obvious/explicit and thus don’t like as well) is to change _performSecureRequest to move the headers["Content-Type"]= post_content_type; line above

 for( var key in this._headers ) {
    if (this._headers.hasOwnProperty(key)) {
      headers[key]= this._headers[key];
    }
  }

That way if you include ‘Content-Type’ in the customHeaders object passed to the OAuth constructor. I don’t love this though due to the obvious/explicit problem I mentioned above and because it forces you to pass all of the parameters before customHeaders when you want to change the content-type.

0reactions
Nogias9xcommented, Jul 23, 2020

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to override default Content-type
I have a minimal-API ( Project Sdk="Microsoft.NET.Sdk.Web" ) app that has a GET endpoint that I would like to return an image/png. The...
Read more >
Content Type value override In Response Rule of Web ...
Hi Experts,. We are facing issues with content type being overridden in response rule of Datapower. Below are the two scenarios : Scenario...
Read more >
How to override content type with Nginx web server
This page explains how to override content type with Nginx web server and verify it with curl command on Linux or Unix-like systems....
Read more >
XMLHttpRequest.overrideMimeType() - Web APIs | MDN
This example specifies a MIME type of "text/plain" , overriding the server's stated type for the data being received. Note: If the server...
Read more >
Impossible to override Content-Type header?
I wonder why the the following code doesn't override an existing Content-Type header: func (writer DiscardBodyResponseWriter) Write(data []byte) (int, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found