Skip to main content

Module http

Module http 

Source
Expand description

Node http module: an HTTP/1.1 server built on top of net.

http.createServer(requestListener) returns a net.Server with an http-specific per-connection hook. As bytes arrive on a connection (posted by the socket reader thread and dispatched on the main thread by net::on_socket_data → http::feed), we buffer them, parse complete HTTP/1.1 requests, and for each one build an IncomingMessage (req) and a ServerResponse (res) and call the user’s (req, res) listener on the main thread. res.end serializes a valid HTTP/1.1 response and writes it straight back to the socket via net::socket_write_id, keeping the connection alive.

Constants§

CLIENT_REQUEST_METHODS
Instance methods of a client ClientRequest (parent wires the ClientRequest tag via native_tag/instance_call).
MODULE_METHODS
http module functions routed through stdlib::call.

Functions§

call
stdlib::call entry for http.<method>.
constant
Non-function http module constants (http.METHODS, http.STATUS_CODES), reachable via namespace_property → stdlib::constant.
construct
stdlib::construct entry for http classes. Parent wires this in.
construct_agent
new http.Agent([options]) — a minimal connection-pool holder. We open a fresh connection per request (no reuse), so the agent only carries its configuration for the JS side to read back.
create_server
Build an HTTP server: a net.Server whose per-connection hook wires up the request parser and remembers the requestListener.
drop_conn
Discard an HTTP connection when its socket closes.
feed
Feed freshly received socket bytes into the HTTP parser. No-op for a socket that is not an HTTP connection (plain net). Runs on the main thread.
instance_call
Instance dispatch for IncomingMessage/ServerResponse (EventEmitter methods handled by net’s shared emitter delegation via stdlib::instance_call).
request
http.request(options|url[, cb]) / http.get(url|options[, cb]). Returns a ClientRequest (a ClientRequest emitter). get auto-sends via .end().
status_table
The status-code → reason-phrase table shared by STATUS_CODES and response serialization.