Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Extend support for post with application/x-www-form-urlencoded #36

Closed
yohay-ma opened this issue Jul 15, 2020 · 3 comments
Closed

Extend support for post with application/x-www-form-urlencoded #36

yohay-ma opened this issue Jul 15, 2020 · 3 comments

Comments

@yohay-ma
Copy link
Contributor

🚀 Feature Proposal

Currently for POST actions fast-proxy support plain/text and application/json.

Motivation

Adding support for additional application/x-www-form-urlencoded

Example

curl -i -H "content-type: application/x-www-form-urlencoded" -X POST -d 'a=1' http://localhost:4000/api/v1/service

Handling the body is likewise:

          if (req.body instanceof Stream) {
            body = req.body
          } else if (typeof req.body === 'string') {
            body = req.body
            populateHeaders(headers, body, 'text/plain')
          } else {
            body = JSON.stringify(req.body)
            populateHeaders(headers, body, 'application/x-www-form-urlencoded')
          }

It should be:

const qs = require('querystring')

          if (req.body instanceof Stream) {
            body = req.body
          } else if (typeof req.body === 'string') {
            body = req.body
            populateHeaders(headers, body, 'text/plain')
          } else if (headers['content-type'] === 'application/x-www-form-urlencoded') {
            const qs = require('querystring');
            body = qs.stringify(req.body)
            populateHeaders(headers, body, 'application/x-www-form-urlencoded')
          } else {
            body = JSON.stringify(req.body)
            populateHeaders(headers, body, 'application/x-www-form-urlencoded')
          }
@yohayg
Copy link
Contributor

yohayg commented Jul 15, 2020

#37

@jkyberneees
Copy link
Collaborator

Thanks once more @yohay-ma, the fix for this issue was merged and will be part of the next release.

@jkyberneees
Copy link
Collaborator

Feature is available in v1.7.0 release.

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

No branches or pull requests

3 participants