Module httpclient

HTTP Client as defined in CommonJS HTTP Client/A.

Class HttpClient

Instance Methods



HttpClient.prototype.connect ()

Open the connection to the URL using the method supplied. If the method or url is missing, throw an error. After connecting, write() will have no effect.


HttpClient.prototype.finish ()

Alias for .connect().read()


HttpClient.prototype.read ()

Read the request and return a JSGI-style object consisting of {status:Integer, headers:Object, body:Iterable}. Calling read() does not block the application until the request is completed, but it does open the input stream such that the data can be read.


HttpClient.prototype.set (key, val)

Set the body, headers, method, or url, or any combination thereof in the settings object. Attribute validity is enforced.

Parameters

key one of body, headers, method or url
val the value to set

HttpClient.prototype.setHeader (key, val)

Set a header on the header object in a case-insensitive manner. That is, if the user sets "content-type", and then later sets "Content-Type", then the first setting is lost.

Parameters

String key header name
String val header value

HttpClient.prototype.setHeaders (headers)

Set a bunch of headers expressed as name-value pairs.

Parameters

headers headers to set

HttpClient.prototype.setOption (key, val)

Parameters

key
val

HttpClient.prototype.write (data)

Append data to the outgoing request, that is, to the iterable body object. This method returns an error if a body was provided earlier via settings that does not implement push.

Parameters

data {Binary} object to write