@@ -371,6 +371,36 @@ srv.listen(1337, '127.0.0.1', () => {
371371Marks the request as aborting. Calling this will cause remaining data
372372in the response to be dropped and the socket to be destroyed.
373373
374+ ### request.addTrailers(headers)
375+
376+ This method adds HTTP trailing headers (a header but at the end of the
377+ message) to the response.
378+
379+ Trailers will ** only** be emitted if chunked encoding is used for the
380+ response; if it is not (e.g., if the request was HTTP/1.0), they will
381+ be silently discarded.
382+
383+ Note that HTTP requires the ` Trailer ` header to be sent if you intend to
384+ emit trailers, with a list of the header fields in its value.
385+
386+ Example:
387+
388+ ``` js
389+ var request = http .request ({
390+ method: ' POST' ,
391+ headers: {
392+ ' Content-Type' : ' text/plain' ,
393+ ' Trailer' : ' Content-MD5'
394+ }
395+ });
396+ request .write (fileData);
397+ request .addTrailers ({' Content-MD5' : ' 7895bf4b8828b55ceaf47747b4bca667' });
398+ request .end ();
399+ ```
400+
401+ Attempting to set a header field name or value that contains invalid characters
402+ will result in a [ ` TypeError ` ] [ ] being thrown.
403+
374404### request.end([ data] [ , encoding ] [ , callback] )
375405
376406Finishes sending the request. If any parts of the body are
@@ -395,6 +425,49 @@ That's usually what you want (it saves a TCP round-trip) but not when the first
395425data isn't sent until possibly much later. ` request.flushHeaders() ` lets you bypass
396426the optimization and kickstart the request.
397427
428+ ### request.getHeader(name)
429+
430+ Reads out a header that's already been queued but not sent to the client. Note
431+ that the name is case insensitive. This can only be called before headers get
432+ implicitly flushed.
433+
434+ Example:
435+
436+ ``` js
437+ var contentType = request .getHeader (' content-type' );
438+ ```
439+
440+ ### request.removeHeader(name)
441+
442+ Removes a header that's queued for implicit sending.
443+
444+ Example:
445+
446+ ``` js
447+ request .removeHeader (' Content-Encoding' );
448+ ```
449+
450+ ### request.setHeader(name, value)
451+
452+ Sets a single header value for implicit headers. If this header already exists
453+ in the to-be-sent headers, its value will be replaced. Use an array of strings
454+ here if you need to send multiple headers with the same name.
455+
456+ Example:
457+
458+ ``` js
459+ request .setHeader (' Content-Type' , ' text/html' );
460+ ```
461+
462+ or
463+
464+ ``` js
465+ request .setHeader (' Set-Cookie' , [' type=ninja' , ' language=javascript' ]);
466+ ```
467+
468+ Attempting to set a header field name or value that contains invalid characters
469+ will result in a [ ` TypeError ` ] [ ] being thrown.
470+
398471### request.setNoDelay([ noDelay] )
399472
400473Once a socket is assigned to this request and is connected
@@ -668,7 +741,9 @@ response; if it is not (e.g., if the request was HTTP/1.0), they will
668741be silently discarded.
669742
670743Note that HTTP requires the ` Trailer ` header to be sent if you intend to
671- emit trailers, with a list of the header fields in its value. E.g.,
744+ emit trailers, with a list of the header fields in its value.
745+
746+ Example:
672747
673748``` js
674749response .writeHead (200 , { ' Content-Type' : ' text/plain' ,
0 commit comments