Trim: docs/api/net.md

This commit is contained in:
tinydew4 2016-11-01 03:05:23 +00:00
parent 721924b749
commit 836cd017a9

View file

@ -12,12 +12,12 @@ The following is a non-exhaustive list of why you may consider using the `net`
module instead of the native Node.js modules: module instead of the native Node.js modules:
* Automatic management of system proxy configuration, support of the wpad * Automatic management of system proxy configuration, support of the wpad
protocol and proxy pac configuration files. protocol and proxy pac configuration files.
* Automatic tunneling of HTTPS requests. * Automatic tunneling of HTTPS requests.
* Support for authenticating proxies using basic, digest, NTLM, Kerberos or * Support for authenticating proxies using basic, digest, NTLM, Kerberos or
negotiate authentication schemes. negotiate authentication schemes.
* Support for traffic monitoring proxies: Fiddler-like proxies used for access * Support for traffic monitoring proxies: Fiddler-like proxies used for access
control and monitoring. control and monitoring.
The `net` module API has been specifically designed to mimic, as closely as The `net` module API has been specifically designed to mimic, as closely as
possible, the familiar Node.js API. The API components including classes, possible, the familiar Node.js API. The API components including classes,
@ -78,22 +78,22 @@ interface and is therefore an [EventEmitter](https://nodejs.org/api/events.html#
### `new ClientRequest(options)` ### `new ClientRequest(options)`
* `options` (Object | String) - If `options` is a String, it is interpreted as * `options` (Object | String) - If `options` is a String, it is interpreted as
the request URL. If it is an object, it is expected to fully specify an HTTP request via the the request URL. If it is an object, it is expected to fully specify an HTTP
following properties: request via the following properties:
* `method` String (optional) - The HTTP request method. Defaults to the GET * `method` String (optional) - The HTTP request method. Defaults to the GET
method. method.
* `url` String (optional) - The request URL. Must be provided in the absolute * `url` String (optional) - The request URL. Must be provided in the absolute
form with the protocol scheme specified as http or https. form with the protocol scheme specified as http or https.
* `session` Object (optional) - The [`Session`](session.md) instance with * `session` Object (optional) - The [`Session`](session.md) instance with
which the request is associated. which the request is associated.
* `partition` String (optional) - The name of the [`partition`](session.md) * `partition` String (optional) - The name of the [`partition`](session.md)
with which the request is associated. Defaults to the empty string. The with which the request is associated. Defaults to the empty string. The
`session` option prevails on `partition`. Thus if a `session` is explicitly `session` option prevails on `partition`. Thus if a `session` is explicitly
specified, `partition` is ignored. specified, `partition` is ignored.
* `protocol` String (optional) - The protocol scheme in the form 'scheme:'. * `protocol` String (optional) - The protocol scheme in the form 'scheme:'.
Currently supported values are 'http:' or 'https:'. Defaults to 'http:'. Currently supported values are 'http:' or 'https:'. Defaults to 'http:'.
* `host` String (optional) - The server host provided as a concatenation of * `host` String (optional) - The server host provided as a concatenation of
the hostname and the port number 'hostname:port' the hostname and the port number 'hostname:port'
* `hostname` String (optional) - The server host name. * `hostname` String (optional) - The server host name.
* `port` Integer (optional) - The server's listening port number. * `port` Integer (optional) - The server's listening port number.
* `path` String (optional) - The path part of the request URL. * `path` String (optional) - The path part of the request URL.
@ -146,6 +146,7 @@ request.on('login', (authInfo, callback) => {
callback('username', 'password') callback('username', 'password')
}) })
``` ```
Providing empty credentials will cancel the request and report an authentication Providing empty credentials will cancel the request and report an authentication
error on the response object: error on the response object:
@ -228,9 +229,9 @@ before first write. Trying to call it after the first write will throw an error.
#### `request.write(chunk[, encoding][, callback])` #### `request.write(chunk[, encoding][, callback])`
* `chunk` (String | Buffer) - A chunk of the request body's data. If it is a * `chunk` (String | Buffer) - A chunk of the request body's data. If it is a
string, it is converted into a Buffer using the specified encoding. string, it is converted into a Buffer using the specified encoding.
* `encoding` String (optional) - Used to convert string chunks into Buffer * `encoding` String (optional) - Used to convert string chunks into Buffer
objects. Defaults to 'utf-8'. objects. Defaults to 'utf-8'.
* `callback` Function (optional) - Called after the write operation ends. * `callback` Function (optional) - Called after the write operation ends.
`callback` is essentially a dummy function introduced in the purpose of keeping `callback` is essentially a dummy function introduced in the purpose of keeping
@ -259,7 +260,6 @@ Cancels an ongoing HTTP transaction. If the request has already emitted the
event will emit `abort` and `close` events. Additionally, if there is an ongoing event will emit `abort` and `close` events. Additionally, if there is an ongoing
response object,it will emit the `aborted` event. response object,it will emit the `aborted` event.
## Class: IncomingMessage ## Class: IncomingMessage
> Handle responses to HTTP/HTTPS requests. > Handle responses to HTTP/HTTPS requests.