ultimate-express 2.0.0 → 2.0.1
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.
- package/package.json +1 -1
- package/src/declarative.js +12 -5
- package/src/response.js +21 -12
package/package.json
CHANGED
package/src/declarative.js
CHANGED
|
@@ -187,10 +187,16 @@ module.exports = function compileDeclarative(cb, app) {
|
|
|
187
187
|
return false;
|
|
188
188
|
}
|
|
189
189
|
const sameHeader = headers.find(header => header[0].toLowerCase() === call.arguments[0].value.toLowerCase());
|
|
190
|
+
let [header, value] = [call.arguments[0].value, call.arguments[1].value];
|
|
191
|
+
if(call.obj.propertyName !== 'setHeader') {
|
|
192
|
+
if(value.includes('text/') && !value.includes('; charset=')) {
|
|
193
|
+
value += '; charset=utf-8';
|
|
194
|
+
}
|
|
195
|
+
}
|
|
190
196
|
if(sameHeader) {
|
|
191
|
-
sameHeader[1] =
|
|
197
|
+
sameHeader[1] = value;
|
|
192
198
|
} else {
|
|
193
|
-
headers.push([
|
|
199
|
+
headers.push([header, value]);
|
|
194
200
|
}
|
|
195
201
|
} else if(call.obj.propertyName === 'append') {
|
|
196
202
|
if(call.arguments[0].type !== 'Literal' || call.arguments[1].type !== 'Literal') {
|
|
@@ -211,6 +217,10 @@ module.exports = function compileDeclarative(cb, app) {
|
|
|
211
217
|
const index = headers.findIndex(header => header[0].toLowerCase() === 'content-type');
|
|
212
218
|
if(index === -1) {
|
|
213
219
|
headers.push(['content-type', 'text/html; charset=utf-8']);
|
|
220
|
+
} else {
|
|
221
|
+
if(headers[index][1].includes('text/') && !headers[index][1].includes('; charset=')) {
|
|
222
|
+
headers[index][1] += '; charset=utf-8';
|
|
223
|
+
}
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
const arg = call.arguments[0];
|
|
@@ -355,9 +365,6 @@ module.exports = function compileDeclarative(cb, app) {
|
|
|
355
365
|
if(header[0].toLowerCase() === 'content-length') {
|
|
356
366
|
return false;
|
|
357
367
|
}
|
|
358
|
-
if(header[0].toLowerCase() === 'content-type' && header[1].includes('text/') && !header[1].includes(';')) {
|
|
359
|
-
header[1] += '; charset=utf-8';
|
|
360
|
-
}
|
|
361
368
|
decRes = decRes.writeHeader(header[0], header[1]);
|
|
362
369
|
}
|
|
363
370
|
|
package/src/response.js
CHANGED
|
@@ -350,7 +350,9 @@ module.exports = class Response extends Writable {
|
|
|
350
350
|
this.headers['content-type'] += '; charset=utf-8';
|
|
351
351
|
}
|
|
352
352
|
} else {
|
|
353
|
-
this.headers['content-type']
|
|
353
|
+
if(!this.headers['content-type']) {
|
|
354
|
+
this.headers['content-type'] = 'application/octet-stream';
|
|
355
|
+
}
|
|
354
356
|
}
|
|
355
357
|
return this.end(body);
|
|
356
358
|
}
|
|
@@ -585,23 +587,17 @@ module.exports = class Response extends Writable {
|
|
|
585
587
|
this.attachment(name);
|
|
586
588
|
this.sendFile(path, opts, done);
|
|
587
589
|
}
|
|
588
|
-
|
|
590
|
+
setHeader(field, value) {
|
|
589
591
|
if(this.headersSent) {
|
|
590
592
|
throw new Error('Cannot set headers after they are sent to the client');
|
|
591
593
|
}
|
|
592
|
-
if(typeof field
|
|
593
|
-
|
|
594
|
-
this.set(header, field[header]);
|
|
595
|
-
}
|
|
594
|
+
if(typeof field !== 'string') {
|
|
595
|
+
throw new TypeError('Header name must be a valid HTTP token');
|
|
596
596
|
} else {
|
|
597
597
|
field = field.toLowerCase();
|
|
598
598
|
if(Array.isArray(value)) {
|
|
599
599
|
this.headers[field] = value;
|
|
600
600
|
return this;
|
|
601
|
-
} else if(field === 'content-type') {
|
|
602
|
-
if(!value.includes('charset=') && (value.startsWith('text/') || value === 'application/json' || value === 'application/javascript')) {
|
|
603
|
-
value += '; charset=utf-8';
|
|
604
|
-
}
|
|
605
601
|
}
|
|
606
602
|
this.headers[field] = String(value);
|
|
607
603
|
}
|
|
@@ -610,8 +606,21 @@ module.exports = class Response extends Writable {
|
|
|
610
606
|
header(field, value) {
|
|
611
607
|
return this.set(field, value);
|
|
612
608
|
}
|
|
613
|
-
|
|
614
|
-
|
|
609
|
+
set(field, value) {
|
|
610
|
+
if(typeof field === 'object') {
|
|
611
|
+
for(const header in field) {
|
|
612
|
+
this.setHeader(header, field[header]);
|
|
613
|
+
}
|
|
614
|
+
} else {
|
|
615
|
+
field = field.toLowerCase();
|
|
616
|
+
if(field === 'content-type') {
|
|
617
|
+
if(!value.includes('charset=') && (value.startsWith('text/') || value === 'application/json' || value === 'application/javascript')) {
|
|
618
|
+
value += '; charset=utf-8';
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
this.setHeader(field, value);
|
|
622
|
+
}
|
|
623
|
+
return this;
|
|
615
624
|
}
|
|
616
625
|
get(field) {
|
|
617
626
|
return this.headers[field.toLowerCase()];
|