@jnode/request 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +6 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jnode/request",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Simple HTTP(s) requesting package for Node.js.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -49,7 +49,10 @@ function request(method = 'GET', url = '', body, headers = {}, options = {}) {
49
49
 
50
50
  // set Content-Disposition header
51
51
  if (!req.getHeader('content-disposition') && (part.name || part.filename || part.disposition)) {
52
- partHeaders['Content-Disposition'] = (part.disposition || 'form-data') + (part.name ? `; name="${part.name}"` : '') + (part.filename ? `; filename="${part.filename}"` : '');
52
+ part.filename = part.filename ? encodeURIComponent(part.filename) : part.filename;
53
+ partHeaders['Content-Disposition'] = (part.disposition || 'form-data') +
54
+ (part.name ? `; name="${part.name}"` : '') +
55
+ (part.filename ? `; filename="${part.filename}"; filename*=UTF-8''${part.filename}` : '');
53
56
  }
54
57
 
55
58
  // write headers and body
@@ -139,11 +142,11 @@ class RequestResponse {
139
142
  }
140
143
 
141
144
  async text(encoding = 'utf8') {
142
- return this['_text_' + encoding] = this['_text_' + encoding] ?? (await this.buffer()).toString(encoding);
145
+ return this['_text_' + encoding] ?? (this['_text_' + encoding] = (await this.buffer()).toString(encoding));
143
146
  }
144
147
 
145
148
  async json(encoding = 'utf8') {
146
- return this['_json_' + encoding] = this['_json_' + encoding] ?? JSON.parse((await this.text(encoding)));
149
+ return this['_json_' + encoding] ?? (this['_json_' + encoding] = JSON.parse(await this.text(encoding)));
147
150
  }
148
151
 
149
152
  rl() {