2016-11-10 20:25:26 +00:00
|
|
|
## Class: IncomingMessage
|
|
|
|
|
|
|
|
> Handle responses to HTTP/HTTPS requests.
|
|
|
|
|
2021-06-15 20:50:31 +00:00
|
|
|
Process: [Main](../glossary.md#main-process)<br />
|
|
|
|
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
`IncomingMessage` implements the [Readable Stream](https://nodejs.org/api/stream.html#stream_readable_streams)
|
2019-07-22 15:20:43 +00:00
|
|
|
interface and is therefore an [EventEmitter][event-emitter].
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
### Instance Events
|
|
|
|
|
|
|
|
#### Event: 'data'
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
* `chunk` Buffer - A chunk of response body's data.
|
|
|
|
|
|
|
|
The `data` event is the usual method of transferring response data into
|
|
|
|
applicative code.
|
|
|
|
|
|
|
|
#### Event: 'end'
|
|
|
|
|
2020-10-06 01:27:30 +00:00
|
|
|
Indicates that response body has ended. Must be placed before 'data' event.
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
#### Event: 'aborted'
|
|
|
|
|
|
|
|
Emitted when a request has been canceled during an ongoing HTTP transaction.
|
|
|
|
|
|
|
|
#### Event: 'error'
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
`error` Error - Typically holds an error string identifying failure root cause.
|
|
|
|
|
|
|
|
Emitted when an error was encountered while streaming response data events. For
|
|
|
|
instance, if the server closes the underlying while the response is still
|
|
|
|
streaming, an `error` event will be emitted on the response object and a `close`
|
|
|
|
event will subsequently follow on the request object.
|
|
|
|
|
|
|
|
### Instance Properties
|
|
|
|
|
|
|
|
An `IncomingMessage` instance has the following readable properties:
|
|
|
|
|
|
|
|
#### `response.statusCode`
|
|
|
|
|
2017-07-24 08:29:03 +00:00
|
|
|
An `Integer` indicating the HTTP response status code.
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
#### `response.statusMessage`
|
|
|
|
|
2021-11-16 04:13:18 +00:00
|
|
|
A `string` representing the HTTP status message.
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
#### `response.headers`
|
|
|
|
|
2020-03-18 02:32:26 +00:00
|
|
|
A `Record<string, string | string[]>` representing the HTTP response headers. The `headers` object is
|
2016-11-10 20:25:26 +00:00
|
|
|
formatted as follows:
|
|
|
|
|
|
|
|
* All header names are lowercased.
|
2020-03-18 02:32:26 +00:00
|
|
|
* Duplicates of `age`, `authorization`, `content-length`, `content-type`,
|
|
|
|
`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,
|
|
|
|
`last-modified`, `location`, `max-forwards`, `proxy-authorization`, `referer`,
|
|
|
|
`retry-after`, `server`, or `user-agent` are discarded.
|
|
|
|
* `set-cookie` is always an array. Duplicates are added to the array.
|
|
|
|
* For duplicate `cookie` headers, the values are joined together with '; '.
|
|
|
|
* For all other headers, the values are joined together with ', '.
|
2016-11-10 20:25:26 +00:00
|
|
|
|
|
|
|
#### `response.httpVersion`
|
|
|
|
|
2021-11-16 04:13:18 +00:00
|
|
|
A `string` indicating the HTTP protocol version number. Typical values are '1.0'
|
2016-11-10 20:25:26 +00:00
|
|
|
or '1.1'. Additionally `httpVersionMajor` and `httpVersionMinor` are two
|
|
|
|
Integer-valued readable properties that return respectively the HTTP major and
|
|
|
|
minor version numbers.
|
2016-11-25 12:17:31 +00:00
|
|
|
|
|
|
|
#### `response.httpVersionMajor`
|
|
|
|
|
2017-07-24 08:29:03 +00:00
|
|
|
An `Integer` indicating the HTTP protocol major version number.
|
2016-11-25 12:17:31 +00:00
|
|
|
|
|
|
|
#### `response.httpVersionMinor`
|
|
|
|
|
2017-07-24 08:29:03 +00:00
|
|
|
An `Integer` indicating the HTTP protocol minor version number.
|
2019-07-22 15:20:43 +00:00
|
|
|
|
|
|
|
[event-emitter]: https://nodejs.org/api/events.html#events_class_eventemitter
|
2022-01-24 16:46:15 +00:00
|
|
|
|
|
|
|
#### `response.rawHeaders`
|
|
|
|
|
|
|
|
A `string[]` containing the raw HTTP response headers exactly as they were
|
|
|
|
received. 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.
|
|
|
|
|
2023-11-21 07:50:08 +00:00
|
|
|
```js @ts-type={response:Electron.IncomingMessage}
|
2022-01-24 16:46:15 +00:00
|
|
|
// Prints something like:
|
|
|
|
//
|
|
|
|
// [ 'user-agent',
|
|
|
|
// 'this is invalid because there can be only one',
|
|
|
|
// 'User-Agent',
|
|
|
|
// 'curl/7.22.0',
|
|
|
|
// 'Host',
|
|
|
|
// '127.0.0.1:8000',
|
|
|
|
// 'ACCEPT',
|
|
|
|
// '*/*' ]
|
2023-06-05 07:26:26 +00:00
|
|
|
console.log(response.rawHeaders)
|
2022-01-24 16:46:15 +00:00
|
|
|
```
|