Constructor
new FetchRequest(options)
- Source:
Properties:
| Name | Type | Default | Description |
|---|---|---|---|
url |
string | full URL where to make request |
|
method |
string |
GET
|
GET, POST, PUT, ... |
port |
int | port to use for localhost if no full URI is provided |
|
headers |
object | object with headers to pass to HTTP request, properties must be all lower case |
|
cookies |
object | an object with cookies to send with request, if even empty rescookies will be set in the response |
|
query |
object | string | additional query parameters to be added to the url as an object or as encoded string |
|
body |
string | object | buffer | if method is GET it is used as query parameters otherwise same as postdata |
|
postdata |
string | object | buffer | data to be sent with the request in the POST body as JSON |
|
file |
string | file name where to save response, in case of error response the error body will be saved as well |
|
stream |
object | a writable stream where to save data |
|
formdata |
object | data to be sent with the POST request as x-www-form-urlencoded, it uses node:querystring to stringify objects |
|
postfile |
string | file to be uploaded in the POST body, not as multipart |
|
postsize |
int | file size to be uploaded if obtained separately |
|
posttype |
string | content type for post data |
|
multipart |
Array.<object> | an array of objects for multipart/form-data post, { name: "..", data: ".." [ file: ".."] }, for files a Buffer can be used in data |
|
noparse |
boolean | do not parse known content types like json, xml |
|
chunked |
boolean | post files using chunked encoding |
|
binary |
boolean | return a Buffer with received data |
|
signer |
function | a function to sign the request signer(this) |
|
checksum |
boolean | if true the body needs a checksum in the signature |
|
streaming |
boolean | if true do not issue req.end to allow more data top send |
|
mtime |
Date | int | a Date or timestamp to be used in conditional requests |
|
conditional |
boolan | add If-Modified-Since header using |
|
httpTimeout |
int | timeout in milliseconds after which the request is aborted if no data received |
|
hardTimeout |
int | abort the request after this amount of time in ms, must be big enough to allow for all data to be received |
|
maxSize |
int | if the content being downloaded becomes greater than this size the request will be aborted |
|
retryCount |
int | how many times to retry the request on error or timeout |
|
retryTimeout |
int | timeout in milliseconds for retries, with every subsequent timeout it will be multiplied by |
|
retryOnError |
boolean | function | retry request if received non 2xx response status, if this is a function then it must return true in order to retry the request, otherwise it is treated as a boolean value, if true then retry on all non-2xx responses |
|
retryPrepare |
function | a function to be called before retrying, it can update any parameter,
retry will use: |
|
errorCount |
int | how many times to retry on aborted connections, default is retryCount |
|
raise |
boolean | on not ok status raise an eror on return with JSON body if present or generic message |
|
noredirects |
boolean | if true then do not follow redirect locations for 30-[1,2,3,7] statuses |
|
preparse |
function | a function to be called before parsing the xml/json content, called in the context of the http object |
|
passheaders |
Array.<string> | a list of headers to be passed in redirects |
|
user |
string | authorization user, if also `password`` is provided then it will use Basic authorization, if only user is provided then Bearer |
|
signal |
AbortSignal | An AbortSignal that may be used to abort an ongoing request. |
|
maxHeaderSize |
number | Optionally overrides the value of --max-http-header-size (the maximum length of response headers in bytes) for responses received from the server. Default: 16384 (16 KiB). |
|
setDefaultHeaders |
boolean | Specifies whether or not to automatically add default headers such as Connection, Content-Length, Transfer-Encoding, and Host. If set to false then all necessary headers must be added manually. Defaults to true. |
|
setHost |
boolean | Specifies whether or not to automatically add the Host header. If provided, this overrides setDefaultHeaders. Defaults to true. |
|
uniqueHeaders |
Array | A list of request headers that should be sent only once. If the header's value is an array, the items will be joined using ; . |
|
joinDuplicateHeaders |
boolean | It joins the field line values of multiple headers in a request with , instead of discarding the duplicates. See message.headers for more information. Default: false. |
|
localAddress |
string | Local interface to bind for network connections. |
|
localPort |
number | Local port to connect from. |
|
data |
string | response data if file was not specified |
|
obj |
object | if the content type is a known type like json or xml this property will hold a reference to the parsed document or null in case or parse error |
|
status |
int | HTTP response status code |
|
date |
Date | Date object with the last modified time of the requested file |
|
resheaders |
object | response headers as an object |
|
rescookies |
object | parsed cookies from the response if request `cookies`` is not empty |
|
size |
int | size of the response body or file |
|
type |
string | response content type |
|
ok |
boolean | true if the status is between 200 and 299 |
Parameters:
| Name | Type | Description |
|---|---|---|
options |
object | properties from FetchRequest |
Methods
parseSetCookies()
- Description:
Parse Set-Cookie header and return an object of cookies: { NAME: { value: VAL, secure: true, expires: N ... } }
- Source: