Comparing version 1.2.5 to 1.2.6
const { request: https } = require('https'); | ||
const { request: http } = require('http'); | ||
const { debuglog } = require('util'); | ||
let erotic = require('erotic'); if (erotic && erotic.__esModule) erotic = erotic.default; | ||
const erotic = require('erotic'); | ||
const { parse } = require('url'); | ||
@@ -15,5 +15,5 @@ const { version } = require('../package.json'); | ||
* @param {AqtOptions} [options] Configuration for requests. | ||
* @param {Object} options.data Optional data to send to the server with the request. | ||
* @param {Object} [options.data] Optional data to send to the server with the request. | ||
* @param {'form'|'json'} [options.type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`. | ||
* @param {OutgoingHttpHeaders} [options.headers] Headers to use for the request. | ||
* @param {http.OutgoingHttpHeaders} [options.headers] Headers to use for the request. | ||
* @param {boolean} [options.compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`. | ||
@@ -63,6 +63,10 @@ * @param {number} [options.timeout] The timeout after which the request should fail. | ||
opts.method = method || 'POST' | ||
opts.headers['Content-Type'] = contentType | ||
opts.headers['Content-Length'] = Buffer.byteLength(data) | ||
if (!('Content-Type' in opts.headers)) { | ||
opts.headers['Content-Type'] = contentType | ||
} | ||
if (!('Content-Length' in opts.headers)) { | ||
opts.headers['Content-Length'] = Buffer.byteLength(data) | ||
} | ||
} | ||
if (compress) { | ||
if (compress && !('Accept-Encoding' in opts.headers)) { | ||
opts.headers['Accept-Encoding'] = 'gzip, deflate' | ||
@@ -95,8 +99,7 @@ } | ||
/** | ||
* @typedef {import('http').OutgoingHttpHeaders} OutgoingHttpHeaders | ||
* | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} AqtOptions Configuration for requests. | ||
* @prop {Object} data Optional data to send to the server with the request. | ||
* @prop {Object} [data] Optional data to send to the server with the request. | ||
* @prop {'form'|'json'} [type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`. | ||
* @prop {OutgoingHttpHeaders} [headers] Headers to use for the request. | ||
* @prop {http.OutgoingHttpHeaders} [headers] Headers to use for the request. | ||
* @prop {boolean} [compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`. | ||
@@ -108,2 +111,6 @@ * @prop {number} [timeout] The timeout after which the request should fail. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('http').OutgoingHttpHeaders} http.OutgoingHttpHeaders | ||
*/ | ||
@@ -113,9 +120,12 @@ | ||
/** | ||
* @typedef {import('http').IncomingHttpHeaders} IncomingHttpHeaders | ||
* | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} AqtReturn | ||
* @prop {string|object|Buffer} body The return from the server. In case the `json` content-type was set by the server, the response will be parsed into an object. If `binary` option was used for the request, a `Buffer` will be returned. Otherwise, a string response is returned. | ||
* @prop {IncomingHttpHeaders} headers Incoming headers returned by the server. | ||
* @prop {string|Object|Buffer} body The return from the server. In case the `json` content-type was set by the server, the response will be parsed into an object. If `binary` option was used for the request, a `Buffer` will be returned. Otherwise, a string response is returned. | ||
* @prop {http.IncomingHttpHeaders} headers Incoming headers returned by the server. | ||
* @prop {number} statusCode The status code returned by the server. | ||
* @prop {string} statusMessage The status message set by the server. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('http').IncomingHttpHeaders} http.IncomingHttpHeaders | ||
*/ |
@@ -1,5 +0,5 @@ | ||
let erotic = require('erotic'); if (erotic && erotic.__esModule) erotic = erotic.default; | ||
const erotic = require('erotic'); | ||
const makeRequest = require('./make-request'); | ||
const getFormData = (form = {}) => { | ||
const getFormData = (form = {}) => { | ||
const urlEncodedDataPairs = Object.keys(form).reduce((acc, key) => { | ||
@@ -15,3 +15,3 @@ const v = form[key] | ||
const getData = (type, data) => { | ||
const getData = (type, data) => { | ||
switch (type) { | ||
@@ -33,3 +33,3 @@ case 'json': | ||
const exec = async (request, requestOptions, | ||
const exec = async (request, requestOptions, | ||
{ data, justHeaders, binary, er = erotic(true) }, | ||
@@ -36,0 +36,0 @@ ) => { |
@@ -1,2 +0,2 @@ | ||
let erotic = require('erotic'); if (erotic && erotic.__esModule) erotic = erotic.default; | ||
const erotic = require('erotic'); | ||
const { collect } = require('catchment'); | ||
@@ -8,3 +8,3 @@ const { createGunzip } = require('zlib'); | ||
*/ | ||
const isMessageGzip = (res) => { | ||
const isMessageGzip = (res) => { | ||
return res.headers['content-encoding'] == 'gzip' | ||
@@ -11,0 +11,0 @@ } |
@@ -0,1 +1,7 @@ | ||
## 3 July 2019 | ||
### [1.2.6](https://github.com/rqt/aqt/compare/v1.2.5...v1.2.6) | ||
- [fix] Don't override passed headers (_Content-Type_, _Content-Length_ and _Accept-Encoding_). | ||
## 16 April 2019 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@rqt/aqt", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "An Advanced Network Request Package That Returns Body (Parsed As JSON If Needed), Headers And Status After Gzip Decompression.", | ||
@@ -11,4 +11,4 @@ "main": "build/index.js", | ||
"test-build": "ALAMODE_ENV=test-build yarn test", | ||
"doc": "NODE_DEBUG=doc doc documentary -o README.md", | ||
"d": "NODE_DEBUG=doc doc src/index.js -g", | ||
"doc": "NODE_DEBUG=doc doc -o README.md", | ||
"d": "typal src/index.js -c -g", | ||
"lint": "eslint .", | ||
@@ -39,2 +39,3 @@ "e": "alanode", | ||
], | ||
"alamode": true, | ||
"author": "Anton <anton@adc.sh>", | ||
@@ -47,8 +48,9 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@idio/core": "^1.3.6", | ||
"documentary": "^1.23.4", | ||
"@idio/idio": "^0.1.0", | ||
"alamode": "^2.3.4", | ||
"documentary": "^1.27.4", | ||
"eslint-config-artdeco": "1.0.1", | ||
"https-context": "^1.0.3", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "^3.11.5" | ||
"zoroaster": "^4.1.1-alpha" | ||
}, | ||
@@ -55,0 +57,0 @@ "dependencies": { |
@@ -24,3 +24,3 @@ # @rqt/aqt | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/0.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/0.svg?sanitize=true"></a></p> | ||
@@ -35,3 +35,3 @@ ## API | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/1.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/1.svg?sanitize=true"></a></p> | ||
@@ -46,12 +46,12 @@ ## `aqt(`<br/> `url: string,`<br/> `options?: AqtOptions,`<br/>`): AqtReturn` | ||
| Name | Type | Description | Default | | ||
| ----------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------- | | ||
| __data*__ | _Object_ | Optional data to send to the server with the request. | - | | ||
| type | _'form' \| 'json'_ | How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. | `'json'` | | ||
| headers | _[http.OutgoingHttpHeaders](#type-httpoutgoinghttpheaders)_ | Headers to use for the request. | - | | ||
| compress | _boolean_ | Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. | `true` | | ||
| timeout | _number_ | The timeout after which the request should fail. | - | | ||
| method | _string_ | What HTTP method to use in making of the request. When no method is given and `data` is present, defaults to `POST`. | - | | ||
| binary | _boolean_ | Whether to return a buffer instead of a string. | `false` | | ||
| justHeaders | _boolean_ | Whether to stop the request after response headers were received, without waiting for the data. | `false` | | ||
| Name | Type | Description | Default | | ||
| ----------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- | -------- | | ||
| data | <em>Object</em> | Optional data to send to the server with the request. | - | | ||
| type | <em>('form' \| 'json')</em> | How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. | `'json'` | | ||
| headers | <em>[http.OutgoingHttpHeaders](#type-httpoutgoinghttpheaders)</em> | Headers to use for the request. | - | | ||
| compress | <em>boolean</em> | Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. | `true` | | ||
| timeout | <em>number</em> | The timeout after which the request should fail. | - | | ||
| method | <em>string</em> | What HTTP method to use in making of the request. When no method is given and `data` is present, defaults to `POST`. | - | | ||
| binary | <em>boolean</em> | Whether to return a buffer instead of a string. | `false` | | ||
| justHeaders | <em>boolean</em> | Whether to stop the request after response headers were received, without waiting for the data. | `false` | | ||
```js | ||
@@ -71,3 +71,3 @@ import aqt from '@rqt/aqt' | ||
"content-type": "text/plain", | ||
"date": "Tue, 16 Apr 2019 14:36:31 GMT", | ||
"date": "Wed, 03 Jul 2019 15:34:47 GMT", | ||
"connection": "close", | ||
@@ -81,3 +81,3 @@ "transfer-encoding": "chunked" | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/2.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/2.svg?sanitize=true"></a></p> | ||
@@ -158,3 +158,3 @@ ## `AqtReturn` Type | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/3.svg?sanitize=true"></a></p> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/3.svg?sanitize=true"></a></p> | ||
@@ -167,3 +167,3 @@ ## Copyright | ||
<a href="https://artd.eco"> | ||
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco" /> | ||
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco"> | ||
</a> | ||
@@ -175,3 +175,3 @@ </th> | ||
<img src="https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif" | ||
alt="Tech Nation Visa" /> | ||
alt="Tech Nation Visa"> | ||
</a> | ||
@@ -181,2 +181,4 @@ </th> | ||
</tr> | ||
</table> | ||
</table> | ||
<p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/-1.svg?sanitize=true"></a></p> |
@@ -15,5 +15,5 @@ import { request as https } from 'https' | ||
* @param {AqtOptions} [options] Configuration for requests. | ||
* @param {Object} options.data Optional data to send to the server with the request. | ||
* @param {Object} [options.data] Optional data to send to the server with the request. | ||
* @param {'form'|'json'} [options.type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`. | ||
* @param {OutgoingHttpHeaders} [options.headers] Headers to use for the request. | ||
* @param {http.OutgoingHttpHeaders} [options.headers] Headers to use for the request. | ||
* @param {boolean} [options.compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`. | ||
@@ -63,6 +63,10 @@ * @param {number} [options.timeout] The timeout after which the request should fail. | ||
opts.method = method || 'POST' | ||
opts.headers['Content-Type'] = contentType | ||
opts.headers['Content-Length'] = Buffer.byteLength(data) | ||
if (!('Content-Type' in opts.headers)) { | ||
opts.headers['Content-Type'] = contentType | ||
} | ||
if (!('Content-Length' in opts.headers)) { | ||
opts.headers['Content-Length'] = Buffer.byteLength(data) | ||
} | ||
} | ||
if (compress) { | ||
if (compress && !('Accept-Encoding' in opts.headers)) { | ||
opts.headers['Accept-Encoding'] = 'gzip, deflate' | ||
@@ -95,8 +99,7 @@ } | ||
/** | ||
* @typedef {import('http').OutgoingHttpHeaders} OutgoingHttpHeaders | ||
* | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} AqtOptions Configuration for requests. | ||
* @prop {Object} data Optional data to send to the server with the request. | ||
* @prop {Object} [data] Optional data to send to the server with the request. | ||
* @prop {'form'|'json'} [type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`. | ||
* @prop {OutgoingHttpHeaders} [headers] Headers to use for the request. | ||
* @prop {http.OutgoingHttpHeaders} [headers] Headers to use for the request. | ||
* @prop {boolean} [compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`. | ||
@@ -108,2 +111,6 @@ * @prop {number} [timeout] The timeout after which the request should fail. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('http').OutgoingHttpHeaders} http.OutgoingHttpHeaders | ||
*/ | ||
@@ -113,9 +120,12 @@ | ||
/** | ||
* @typedef {import('http').IncomingHttpHeaders} IncomingHttpHeaders | ||
* | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} AqtReturn | ||
* @prop {string|object|Buffer} body The return from the server. In case the `json` content-type was set by the server, the response will be parsed into an object. If `binary` option was used for the request, a `Buffer` will be returned. Otherwise, a string response is returned. | ||
* @prop {IncomingHttpHeaders} headers Incoming headers returned by the server. | ||
* @prop {string|Object|Buffer} body The return from the server. In case the `json` content-type was set by the server, the response will be parsed into an object. If `binary` option was used for the request, a `Buffer` will be returned. Otherwise, a string response is returned. | ||
* @prop {http.IncomingHttpHeaders} headers Incoming headers returned by the server. | ||
* @prop {number} statusCode The status code returned by the server. | ||
* @prop {string} statusMessage The status message set by the server. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {import('http').IncomingHttpHeaders} http.IncomingHttpHeaders | ||
*/ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30514
480
175
7