@@ -587,13 +587,24 @@ added: v1.6.0
587
587
-->
588
588
589
589
* ` name ` {string}
590
- * Returns: {string }
590
+ * Returns: {any }
591
591
592
592
Reads out a header on the request. Note that the name is case insensitive.
593
+ The type of the return value depends on the arguments provided to
594
+ [ ` request.setHeader() ` ] [ ] .
593
595
594
596
Example:
595
597
``` js
598
+ request .setHeader (' content-type' , ' text/html' );
599
+ request .setHeader (' Content-Length' , Buffer .byteLength (body));
600
+ request .setHeader (' Set-Cookie' , [' type=ninja' , ' language=javascript' ]);
596
601
const contentType = request .getHeader (' Content-Type' );
602
+ // contentType is 'text/html'
603
+ const contentLength = request .getHeader (' Content-Length' );
604
+ // contentLength is of type number
605
+ const setCookie = request .getHeader (' set-cookie' );
606
+ // setCookie is of type string[]
607
+
597
608
```
598
609
599
610
### request.removeHeader(name)
@@ -616,11 +627,14 @@ added: v1.6.0
616
627
-->
617
628
618
629
* ` name ` {string}
619
- * ` value ` {string }
630
+ * ` value ` {any }
620
631
621
632
Sets a single header value for headers object. If this header already exists in
622
633
the to-be-sent headers, its value will be replaced. Use an array of strings
623
- here to send multiple headers with the same name.
634
+ here to send multiple headers with the same name. Non-string values will be
635
+ stored without modification. Therefore, [ ` request.getHeader() ` ] [ ] may return
636
+ non-string values. However, the non-string values will be converted to strings
637
+ for network transmission.
624
638
625
639
Example:
626
640
``` js
@@ -1085,15 +1099,24 @@ added: v0.4.0
1085
1099
-->
1086
1100
1087
1101
* ` name ` {string}
1088
- * Returns: {string }
1102
+ * Returns: {any }
1089
1103
1090
1104
Reads out a header that's already been queued but not sent to the client.
1091
- Note that the name is case insensitive.
1105
+ Note that the name is case insensitive. The type of the return value depends
1106
+ on the arguments provided to [ ` response.setHeader() ` ] [ ] .
1092
1107
1093
1108
Example:
1094
1109
1095
1110
``` js
1111
+ response .setHeader (' Content-Type' , ' text/html' );
1112
+ response .setHeader (' Content-Length' , Buffer .byteLength (body));
1113
+ response .setHeader (' Set-Cookie' , [' type=ninja' , ' language=javascript' ]);
1096
1114
const contentType = response .getHeader (' content-type' );
1115
+ // contentType is 'text/html'
1116
+ const contentLength = response .getHeader (' Content-Length' );
1117
+ // contentLength is of type number
1118
+ const setCookie = response .getHeader (' set-cookie' );
1119
+ // setCookie is of type string[]
1097
1120
```
1098
1121
1099
1122
### response.getHeaderNames()
@@ -1204,11 +1227,14 @@ added: v0.4.0
1204
1227
-->
1205
1228
1206
1229
* ` name ` {string}
1207
- * ` value ` {string | string [ ] }
1230
+ * ` value ` {any }
1208
1231
1209
1232
Sets a single header value for implicit headers. If this header already exists
1210
1233
in the to-be-sent headers, its value will be replaced. Use an array of strings
1211
- here to send multiple headers with the same name.
1234
+ here to send multiple headers with the same name. Non-string values will be
1235
+ stored without modification. Therefore, [ ` response.getHeader() ` ] [ ] may return
1236
+ non-string values. However, the non-string values will be converted to strings
1237
+ for network transmission.
1212
1238
1213
1239
Example:
1214
1240
@@ -2013,11 +2039,14 @@ not abort the request or do anything besides add a `'timeout'` event.
2013
2039
[ `net.createConnection()` ] : net.html#net_net_createconnection_options_connectlistener
2014
2040
[ `removeHeader(name)` ] : #http_request_removeheader_name
2015
2041
[ `request.end()` ] : #http_request_end_data_encoding_callback
2042
+ [ `request.getHeader()` ] : #http_request_getheader_name
2043
+ [ `request.setHeader()` ] : #http_request_setheader_name_value
2016
2044
[ `request.setTimeout()` ] : #http_request_settimeout_timeout_callback
2017
2045
[ `request.socket` ] : #http_request_socket
2018
2046
[ `request.socket.getPeerCertificate()` ] : tls.html#tls_tlssocket_getpeercertificate_detailed
2019
2047
[ `request.write(data, encoding)` ] : #http_request_write_chunk_encoding_callback
2020
2048
[ `response.end()` ] : #http_response_end_data_encoding_callback
2049
+ [ `response.getHeader()` ] : #http_response_getheader_name
2021
2050
[ `response.setHeader()` ] : #http_response_setheader_name_value
2022
2051
[ `response.socket` ] : #http_response_socket
2023
2052
[ `response.write()` ] : #http_response_write_chunk_encoding_callback
0 commit comments