In particular, large, possibly chunk-encoded, messages. The interface is careful to nodejs get request buffer entire requests or responses — the user is able to stream data. It deals with stream handling and message parsing only. It parses a message into headers and body but it does not parse the actual headers or the body. See for details on how duplicate headers nodejs get request handled. It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to nodejs get request same host and port. Whether it is destroyed or pooled depends on the keepAlive. Servers may also refuse to allow multiple requests over the same connection, in which case the connection will have to nodejs get request remade for every request and cannot be pooled. The Agent will still make the requests to that server, but each one will occur over a new connection. When a connection is closed by the client or the server, it is removed from the pool. Any unused sockets in the pool will be unrefed so as not to keep the Node. Sockets are removed from an agent when the socket emits either a 'close' event or an 'agentRemove' event. By providing agent: false as an option to the http. Ignored when the keepAlive option is false or undefined. Only relevant if keepAlive is set to true. This will set the timeout after the socket is connected. The default that is used by has all of these values set to their respective defaults. To configure any of them, a custom instance must be created. Agent keepAlive: true ; options. By default, this function is the same as. However, custom agents may override this method in case greater flexibility is desired. Default behavior is to: socket. If this method returns a falsy value, the socket will be destroyed instead of persisting it for use with the next request. It is usually not necessary to do this. However, if using an agent with keepAlive enabled, then it is best to explicitly shut down the agent when it will no longer be used. Otherwise, sockets may hang open for quite a long time before the server terminates them. It represents an in-progress request whose header has nodejs get request been queued. The actual header will be nodejs get request along with the first data chunk or when calling. To get the response, add a listener for to the request object. The event is executed with one argument which is an instance of. During the event, one can add listeners to the response object; particularly to listen for the 'data' event. If no handler is added, then the response will be entirely discarded. However, if a event handler is added, then the data from the response object must be consumed, either by calling response. Until the data is consumed, the 'end' event will not fire. Also, until the data is read it will consume memory that can eventually lead to a 'process out of memory' error. The request inherits fromand additionally implements the following: Event: 'abort' Nodejs get request in: v0. This event is emitted with a callback containing an object with a status code. To be notified of 101 Upgrade notices, listen for the event instead. Event: 'response' Added in: v0. If this event is not being listened for and the response status code is 101 Switching Protocols, clients receiving an upgrade header will have their connections closed. A client server pair demonstrating how to listen for the 'upgrade' event. If any parts of the body are unsent, it will flush them to the stream. If data is specified, it is equivalent to calling followed by request. If callback is specified, it will be called when the request stream is finished. Note that the name is case insensitive. The type of the return value depends on the arguments provided to. If set to 0, no limit will be applied. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same nodejs get request. Non-string values will be stored without modification. Therefore, may return non-string values. However, the non-string values will be converted to strings for network transmission. Usually users will not want to access this property. In particular, the socket will not emit 'readable' events because of how the protocol parser attaches to the socket. The socket may also be accessed via request. The encoding argument is optional and only applies when chunk is a string. The callback argument is optional and will be called when this chunk of data is flushed, but only if the chunk is non-empty. Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the nodejs get request was queued in user memory. When write function is called with empty string or buffer, it does nothing and waits for more input. If this event is not listened for, the server will automatically respond with a 100 Continue as appropriate. Note that when this event is emitted and handled, the event will not be emitted. Event: 'checkExpectation' Added in: v5. If this event is not listened for, the server will automatically respond with a 417 Expectation Failed as appropriate. Note that when this event is emitted and handled, the event will not be emitted. Event: 'clientError' History Version Changes v9. Adding this buffer to the error object of 'clientError' event is to make it possible that developers can log the broken packet. Event: 'close' Added in: v0. After this event is emitted, the request's socket will not have a 'data' event listener, meaning it will need to be bound in order to handle data sent to the server on that socket. Event: 'connection' Added in: v0. Usually users will not want to access this event. In particular, the socket will not emit 'readable' events because of how the protocol parser attaches to the socket. The socket can also be accessed at request. In that case, any stream can be passed. Event: 'request' History Version Changes v10. Listening to this event is optional and clients cannot insist on a protocol change. After this event is emitted, the request's socket will not have a 'data' event listener, meaning it will need to be bound in order to handle data sent to the server on that socket. In case of inactivity, the rules defined in apply. However, that inactivity based timeout would still allow the connection to be kept open if the headers are being sent very slowly by default, up to a byte per 2 minutes. In order to prevent this, whenever header data arrives an additional check is made that more than server. If the check fails, a 'timeout' event is emitted on the server object, and by default the socket is destroyed. See for more information on how timeout behavior can be customized. This method is identical to from. If there is a 'timeout' event listener on the Server object, then it will be called with the timed-out socket as an argument. By default, the Server's timeout value is 2 minutes, and sockets are destroyed automatically if they time out. However, if a callback is assigned to the Server's 'timeout' event, timeouts must be handled explicitly. The number of milliseconds of inactivity nodejs get request a socket is presumed to have timed out. A value of 0 will disable the timeout behavior on incoming connections. The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections. The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. If the server receives new data before the keep-alive timeout has fired, it will nodejs get request the regular inactivity timeout, i. A value of 0 will disable the keep-alive timeout behavior on incoming connections. A value of 0 makes the http server behave similarly to Node. The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections. More specifically, this event is emitted when the last segment of the response headers and body have been handed off to the operating system for transmission over the network. It does not imply that the client has received anything yet. Trailers will only be emitted if chunked encoding is used for the response; if it is not e. If data is specified, it is equivalent to calling followed by response. If callback is specified, it will be called when the response stream is finished. Note that the name is case insensitive. The type of the return value depends on the arguments provided to. All header names are lowercase. Since a shallow copy is used, array values may be mutated without additional calls to various header-related http module methods. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase. The object returned by the response. This means that typical Object methods such as obj. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name. Non-string values will be stored without modification. Therefore, may return non-string values. However, the non-string values will be converted to strings for network transmission. Nodejs get request headers have been set withthey will be merged with any headers passed towith the headers passed to given precedence. If progressive population of headers is desired with potential future retrieval and modification, use instead of. If a callback is provided, then it is added as a listener on the 'timeout' event on the response object. If no 'timeout' listener is added to the request, the response, or the server, then sockets are destroyed when they time out. If a handler is assigned to the request, the response, or the server's 'timeout' events, timed out sockets must be handled explicitly. Usually users will not want to access this property. In particular, the socket will not emit 'readable' events because of how the protocol parser attaches to the socket. The socket may also be accessed via response. If this is left as undefined then the standard message for the status code will be used. This sends a chunk of the response body. This method may be called multiple times to provide successive parts of the body. Similarly, the 204 and 304 responses must not include a message body. If chunk is a string, the second parameter specifies how to encode it into a byte stream. The first time is called, it will send the buffered header information and the first chunk of the body to the client. The second time is called, Node. That is, the response is buffered up to the first chunk of the body. Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. The last argument, headers, are the response headers. Optionally one can give a human-readable statusMessage as the second argument. When headers have been set withthey will be merged with any headers passed towith the headers passed to given precedence. If this method is called and has not been called, it will directly write the supplied header values onto the network channel without caching internally, and the on the header will not yield the expected result. If progressive population of headers is desired with potential future retrieval and modification, use instead. The above example works because the string 'hello world' contains only single byte characters. If the body contains higher coded characters then Buffer. Attempting to set a header field name or value that contains invalid characters will nodejs get request in a being thrown. Key-value pairs of header names and values. Duplicates are added to the array. Note that the keys and values are in the same list. It is not a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. Header names are not lowercased, and duplicates are not merged. Useful for extending the original IncomingMessage. Useful for extending the original ServerResponse. The requestListener is a function which is automatically added to the event. Properties that are inherited from the prototype are ignored. Note that the callback must take care to consume the response data for reasons stated in section. The callback is invoked with a single argument that is an instance of. To supporthostname will be used if both host and nodejs get request are specified. Valid values are 4 or 6. Should include query string if any. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future. This can be used to avoid creating a custom Agent class just to override the default createConnection function. Any stream is a valid return value. This will set the timeout before the socket is connected. This function allows one to transparently issue requests. If url is a string, it is automatically parsed with. If it is a object, it will be automatically converted to an ordinary options object. If both url and options are specified, the objects are merged, with the options properties taking precedence. The optional callback parameter will be added as a one-time listener for the event. The ClientRequest instance is a writable stream. As with all 'error' events, if no listeners are registered the error will be thrown. There are a few special headers that should be noted. Usually, when sending 'Expect: 100-continue', both a timeout and a listener for the 'continue' event should be set.