Content-Type doesn't work correctly
See original GitHub issueI’m trying to make POST request and send JSON data to Azure Function using application/json
Content-Type. But the function call hangs and return timeout instead of result.
App has the following configuration
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Locally such expressjs application works perfectly. But looks like some trouble with Content-Type on Azure.
However when I change configuration to this one
app.use(bodyParser.json({ type: 'application/*+json' }));
app.use(bodyParser.urlencoded({ extended: true }));
My POST requests pass. But for x-www-form-urlencoded
it still can’t parse the data and returns timeout.
Could you please help me to understand why it doesn’t work? Thank you
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
How To Fix Invalid Content-Type Text HTML - Sitechecker
Learn how to fix invalid Content-Type text HTML errors. We'll show you how to fix the URL and linked data in your web...
Read more >Setting 'Content-Type' header does not work. #2544 - GitHub
It seems like setting Content-Type header is impossible without data property: const api = Axios.create({ baseURL: 'https://my-url', ...
Read more >Content-type not working in PHP - Stack Overflow
I have some issues with a PHP file that is not working properly. The Content-type does not get recieved by any browser at...
Read more >Add a content type to a list or library - Microsoft Support
Under Content Types, select Add from existing site content types. If Content Types doesn't appear, select Advanced settings, and select Yes under Allow...
Read more >Exposed filter doesn't work properly with content type - Drupal
Exposed filter doesn't work with content type, Show all content types even not selected once. And also wrong default value instead of All...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
application/*+json
is not actually the way. I did some trick to manage bodyParser stuff.So here I check first the environment. If it’s not azure then just follow usual express bodyParser style. For azure environment I created custom middleware to handle request object.
This can be different. You can add more checks if you want. So basically for
application/json
content-type azure itself fulfillreq.body
object with proper request data as json object. Forapplication/x-www-form-urlencoded
content-type data comes in raw format, so I used query-string library to parse incoming data and fulfillreq.body
with json object.For your case with multer I didn’t try anything actually. I assume data will come as buffer object, and you should add one more check for content-type
application/octet-stream
and parse it by yourself, maybe using some existing libraries. But I’m not sure, you better try yourself, I may be wrong.@iredjee I think it might not so much to do with the content-type, but the same cause as #22 - if the request object isn’t a stream, then it can’t pipe the original request body into a stream-consuming JSON parser. The original code just did a NOOP if it tried to be used as a stream - hence why it might have just timed out. Changing the request object to extend a stream (as it is in express) might be the fix (I hope).
edit: if you’d like to try it out, you can change your package.json to use: