@@ -286,9 +286,9 @@ added: v0.1.17
286
286
287
287
This object is created internally and returned from [ ` http.request() ` ] [ ] . It
288
288
represents an _ in-progress_ request whose header has already been queued. The
289
- header is still mutable using the ` setHeader(name, value) ` , ` getHeader(name) ` ,
290
- ` removeHeader(name) ` API. The actual header will be sent along with the first
291
- data chunk or when calling [ ` request.end() ` ] [ ] .
289
+ header is still mutable using the [ ` setHeader(name, value) ` ] [ ] ,
290
+ [ ` getHeader(name) ` ] [ ] , [ ` removeHeader(name) ` ] [ ] API. The actual header will
291
+ be sent along with the first data chunk or when calling [ ` request.end() ` ] [ ] .
292
292
293
293
To get the response, add a listener for [ ` 'response' ` ] [ ] to the request object.
294
294
[ ` 'response' ` ] [ ] will be emitted from the request object when the response
@@ -552,6 +552,58 @@ That's usually desired (it saves a TCP round-trip), but not when the first
552
552
data is not sent until possibly much later. ` request.flushHeaders() ` bypasses
553
553
the optimization and kickstarts the request.
554
554
555
+ ### request.getHeader(name)
556
+ <!-- YAML
557
+ added: v1.6.0
558
+ -->
559
+
560
+ * ` name ` {string}
561
+ * Returns: {string}
562
+
563
+ Reads out a header on the request. Note that the name is case insensitive.
564
+
565
+ Example:
566
+ ``` js
567
+ const contentType = request .getHeader (' Content-Type' );
568
+ ```
569
+
570
+ ### request.removeHeader(name)
571
+ <!-- YAML
572
+ added: v1.6.0
573
+ -->
574
+
575
+ * ` name ` {string}
576
+
577
+ Removes a header that's already defined into headers object.
578
+
579
+ Example:
580
+ ``` js
581
+ request .removeHeader (' Content-Type' );
582
+ ```
583
+
584
+ ### request.setHeader(name, value)
585
+ <!-- YAML
586
+ added: v1.6.0
587
+ -->
588
+
589
+ * ` name ` {string}
590
+ * ` value ` {string}
591
+
592
+ Sets a single header value for headers object. If this header already exists in
593
+ the to-be-sent headers, its value will be replaced. Use an array of strings
594
+ here to send multiple headers with the same name.
595
+
596
+ Example:
597
+ ``` js
598
+ request .setHeader (' Content-Type' , ' application/json' );
599
+ ```
600
+
601
+ or
602
+
603
+ ``` js
604
+ request .setHeader (' Set-Cookie' , [' type=ninja' , ' language=javascript' ]);
605
+ ```
606
+
555
607
### request.setNoDelay([ noDelay] )
556
608
<!-- YAML
557
609
added: v0.5.9
@@ -1904,6 +1956,7 @@ const req = http.request(options, (res) => {
1904
1956
[ `agent.createConnection()` ] : #http_agent_createconnection_options_callback
1905
1957
[ `agent.getName()` ] : #http_agent_getname_options
1906
1958
[ `destroy()` ] : #http_agent_destroy
1959
+ [ `getHeader(name)` ] : #requestgetheadername
1907
1960
[ `http.Agent` ] : #http_class_http_agent
1908
1961
[ `http.ClientRequest` ] : #http_class_http_clientrequest
1909
1962
[ `http.IncomingMessage` ] : #http_class_http_incomingmessage
@@ -1918,6 +1971,7 @@ const req = http.request(options, (res) => {
1918
1971
[ `net.Server` ] : net.html#net_class_net_server
1919
1972
[ `net.Socket` ] : net.html#net_class_net_socket
1920
1973
[ `net.createConnection()` ] : net.html#net_net_createconnection_options_connectlistener
1974
+ [ `removeHeader(name)` ] : #requestremoveheadername
1921
1975
[ `request.end()` ] : #http_request_end_data_encoding_callback
1922
1976
[ `request.setTimeout()` ] : #http_request_settimeout_timeout_callback
1923
1977
[ `request.socket` ] : #http_request_socket
@@ -1931,6 +1985,7 @@ const req = http.request(options, (res) => {
1931
1985
[ `response.writeContinue()` ] : #http_response_writecontinue
1932
1986
[ `response.writeHead()` ] : #http_response_writehead_statuscode_statusmessage_headers
1933
1987
[ `server.timeout` ] : #http_server_timeout
1988
+ [ `setHeader(name, value)` ] : #requestsetheadername-value
1934
1989
[ `socket.setKeepAlive()` ] : net.html#net_socket_setkeepalive_enable_initialdelay
1935
1990
[ `socket.setNoDelay()` ] : net.html#net_socket_setnodelay_nodelay
1936
1991
[ `socket.setTimeout()` ] : net.html#net_socket_settimeout_timeout_callback
0 commit comments