jhiesey / stream-http

Streaming node http in the browser
MIT License
354 stars 62 forks source link

Allow Request Body for custom HTTP verbs other than POST, PUT and PATCH. #69

Closed angelkenneth closed 7 years ago

angelkenneth commented 7 years ago

Hi Guys, to give context, i am using Angular 2 and Typescript, my server is Django, and stream-http==2.6.3.

My server provides a custom verb named GETX, and its purpose is to have the query parameters be its body instead of being part of its URL. This is to solve the URL length limit problem with servers and to retrieve a specific set of data by using a more complex query.

Instead of:

GET /foo?query=1

We use:

GETX /foo
Content-Type: application/json
{"query":1}

Both calls below work in the NodeJS shell but when compiling it using ng build then serving them to the browser: GETX does not have a body.

let request = require('request');

request({  // #1
    url: "http://localhost:7000/api/blog-articles",
    method: "POST", json: {foo: 1}
    }, (err, res, body) => console.log(res.request.body));
request({  // #2
    url: "http://localhost:7000/api/blog-articles",
    method: "GETX", json: {foo: 1}
    }, (err, res, body) => console.log(res.request.body));

The code that prevents me from using a body for custom verbs is lib/request.js:102 of this project:

if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH' || opts.method === 'MERGE') {
...

May i ask that custom verbs be allowed to have a body or some sort of option to allow such?

jhiesey commented 7 years ago

Fix released in v2.7.0