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

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

@yohay-ma

Description

@yohay-ma

🚀 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')
          }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions