Skip to content

Allow method in HTTP requests #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fs/api_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let HTTP = {
// error string, `data` - optional object with request parameters.
// By default, `GET` method is used. If `data` is specified, POST method
// is used, the `data` object gets `JSON.stringify()`-ed and used as a
// HTTP message body.
// HTTP message body unless `method` is set.
//
// In order to send HTTPS request, use `https://...` URL. Note that in that
// case `ca.pem` file must contain CA certificate of the requested server.
Expand All @@ -65,6 +65,7 @@ let HTTP = {
// ```javascript
// HTTP.query({
// url: 'http://httpbin.org/post',
// method: 'POST', // Optional method
// headers: { 'X-Foo': 'bar' }, // Optional - headers
// data: {foo: 1, bar: 'baz'}, // Optional. If set, JSON-encoded and POST-ed
// success: function(body, full_http_msg) { print(body); },
Expand All @@ -82,7 +83,7 @@ let HTTP = {
let opts = ud.opts;
let body = opts.data || '';
if (typeof(body) !== 'string') body = JSON.stringify(body);
let meth = body ? 'POST' : 'GET';
let meth = opts.method || (body ? 'POST' : 'GET');
let host = 'Host: ' + ud.u.addr + '\r\n';
let cl = 'Content-Length: ' + JSON.stringify(body.length) + '\r\n';
let hdrs = opts.headers || {};
Expand Down