Skip to content

Commit bc9c2ca

Browse files
shfshanyueBethGriggs
authored andcommitted
http: remove CRLF variable
PR-URL: #40101 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 31994fb commit bc9c2ca

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

‎lib/_http_common.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ module.exports = {
268268
_checkIsHttpToken: checkIsHttpToken,
269269
chunkExpression: /(?:^|\W)chunked(?:$|\W)/i,
270270
continueExpression: /(?:^|\W)100-continue(?:$|\W)/i,
271-
CRLF: '\r\n',
271+
CRLF: '\r\n',// TODO: Deprecate this.
272272
freeParser,
273273
methods,
274274
parsers,

‎lib/_http_outgoing.js‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ const Stream = require('stream');
4545
constinternalUtil=require('internal/util');
4646
const{ kOutHeaders, utcDate, kNeedDrain }=require('internal/http');
4747
const{ Buffer }=require('buffer');
48-
constcommon=require('_http_common');
49-
constcheckIsHttpToken=common._checkIsHttpToken;
50-
constcheckInvalidHeaderChar=common._checkInvalidHeaderChar;
48+
const{
49+
_checkIsHttpToken: checkIsHttpToken,
50+
_checkInvalidHeaderChar: checkInvalidHeaderChar,
51+
chunkExpression: RE_TE_CHUNKED,
52+
}=require('_http_common');
5153
const{
5254
defaultTriggerAsyncIdScope,
5355
symbols: { async_id_symbol }
@@ -78,14 +80,12 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
7880
});
7981

8082
constHIGH_WATER_MARK=getDefaultHighWaterMark();
81-
const{CRLF}=common;
8283

8384
constkCorked=Symbol('corked');
8485

8586
constnop=()=>{};
8687

8788
constRE_CONN_CLOSE=/(?:^|\W)close(?:$|\W)/i;
88-
constRE_TE_CHUNKED=common.chunkExpression;
8989

9090
// isCookieField performs a case-insensitive comparison of a provided string
9191
// against the word "cookie." As of V8 6.6 this is faster than handrolling or
@@ -417,7 +417,7 @@ function _storeHeader(firstLine, headers) {
417417

418418
// Date header
419419
if(this.sendDate&&!state.date){
420-
header+='Date: '+utcDate()+CRLF;
420+
header+='Date: '+utcDate()+'\r\n';
421421
}
422422

423423
// Force the connection to close when the response is a 204 No Content or
@@ -447,14 +447,14 @@ function _storeHeader(firstLine, headers) {
447447
constshouldSendKeepAlive=this.shouldKeepAlive&&
448448
(state.contLen||this.useChunkedEncodingByDefault||this.agent);
449449
if(shouldSendKeepAlive){
450-
header+='Connection: keep-alive'+CRLF;
450+
header+='Connection: keep-alive\r\n';
451451
if(this._keepAliveTimeout&&this._defaultKeepAlive){
452452
consttimeoutSeconds=MathFloor(this._keepAliveTimeout/1000);
453-
header+=`Keep-Alive: timeout=${timeoutSeconds}${CRLF}`;
453+
header+=`Keep-Alive: timeout=${timeoutSeconds}\r\n`;
454454
}
455455
}else{
456456
this._last=true;
457-
header+='Connection: close'+CRLF;
457+
header+='Connection: close\r\n';
458458
}
459459
}
460460

@@ -467,9 +467,9 @@ function _storeHeader(firstLine, headers) {
467467
}elseif(!state.trailer&&
468468
!this._removedContLen&&
469469
typeofthis._contentLength==='number'){
470-
header+='Content-Length: '+this._contentLength+CRLF;
470+
header+='Content-Length: '+this._contentLength+'\r\n';
471471
}elseif(!this._removedTE){
472-
header+='Transfer-Encoding: chunked'+CRLF;
472+
header+='Transfer-Encoding: chunked\r\n';
473473
this.chunkedEncoding=true;
474474
}else{
475475
// We should only be able to get here if both Content-Length and
@@ -487,7 +487,7 @@ function _storeHeader(firstLine, headers) {
487487
thrownewERR_HTTP_TRAILER_INVALID();
488488
}
489489

490-
this._header=header+CRLF;
490+
this._header=header+'\r\n';
491491
this._headerSent=false;
492492

493493
// Wait until the first body chunk, or close(), is sent to flush,
@@ -514,7 +514,7 @@ function processHeader(self, state, key, value, validate) {
514514
functionstoreHeader(self,state,key,value,validate){
515515
if(validate)
516516
validateHeaderValue(key,value);
517-
state.header+=key+': '+value+CRLF;
517+
state.header+=key+': '+value+'\r\n';
518518
matchHeader(self,state,key,value);
519519
}
520520

@@ -694,7 +694,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableNeedDrain', {
694694
}
695695
});
696696

697-
constcrlf_buf=Buffer.from(CRLF);
697+
constcrlf_buf=Buffer.from('\r\n');
698698
OutgoingMessage.prototype.write=functionwrite(chunk,encoding,callback){
699699
if(typeofencoding==='function'){
700700
callback=encoding;
@@ -818,7 +818,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
818818
debug('Trailer "%s" contains invalid characters',field);
819819
thrownewERR_INVALID_CHAR('trailer content',field);
820820
}
821-
this._trailer+=field+': '+value+CRLF;
821+
this._trailer+=field+': '+value+'\r\n';
822822
}
823823
};
824824

‎lib/_http_server.js‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const assert = require('internal/assert');
3737
const{
3838
parsers,
3939
freeParser,
40-
CRLF,
4140
continueExpression,
4241
chunkExpression,
4342
kIncomingMessage,
@@ -254,12 +253,12 @@ ServerResponse.prototype.detachSocket = function detachSocket(socket) {
254253
};
255254

256255
ServerResponse.prototype.writeContinue=functionwriteContinue(cb){
257-
this._writeRaw(`HTTP/1.1 100 Continue${CRLF}${CRLF}`,'ascii',cb);
256+
this._writeRaw('HTTP/1.1 100 Continue\r\n\r\n','ascii',cb);
258257
this._sent100=true;
259258
};
260259

261260
ServerResponse.prototype.writeProcessing=functionwriteProcessing(cb){
262-
this._writeRaw(`HTTP/1.1 102 Processing${CRLF}${CRLF}`,'ascii',cb);
261+
this._writeRaw('HTTP/1.1 102 Processing\r\n\r\n','ascii',cb);
263262
};
264263

265264
ServerResponse.prototype._implicitHeader=function_implicitHeader(){
@@ -322,7 +321,7 @@ function writeHead(statusCode, reason, obj) {
322321
if(checkInvalidHeaderChar(this.statusMessage))
323322
thrownewERR_INVALID_CHAR('statusMessage');
324323

325-
conststatusLine=`HTTP/1.1 ${statusCode}${this.statusMessage}${CRLF}`;
324+
conststatusLine=`HTTP/1.1 ${statusCode}${this.statusMessage}\r\n`;
326325

327326
if(statusCode===204||statusCode===304||
328327
(statusCode>=100&&statusCode<=199)){
@@ -648,16 +647,16 @@ function onParserTimeout(server, socket) {
648647

649648
constnoop=()=>{};
650649
constbadRequestResponse=Buffer.from(
651-
`HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}`+
652-
`Connection: close${CRLF}${CRLF}`,'ascii'
650+
`HTTP/1.1 400 ${STATUS_CODES[400]}\r\n`+
651+
'Connection: close\r\n\r\n','ascii'
653652
);
654653
constrequestTimeoutResponse=Buffer.from(
655-
`HTTP/1.1 408 ${STATUS_CODES[408]}${CRLF}`+
656-
`Connection: close${CRLF}${CRLF}`,'ascii'
654+
`HTTP/1.1 408 ${STATUS_CODES[408]}\r\n`+
655+
'Connection: close\r\n\r\n','ascii'
657656
);
658657
constrequestHeaderFieldsTooLargeResponse=Buffer.from(
659-
`HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}`+
660-
`Connection: close${CRLF}${CRLF}`,'ascii'
658+
`HTTP/1.1 431 ${STATUS_CODES[431]}\r\n`+
659+
'Connection: close\r\n\r\n','ascii'
661660
);
662661
functionsocketOnError(e){
663662
// Ignore further errors

0 commit comments

Comments
 (0)