| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 33b03b2 commit b43caf9
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1803,10 +1803,10 @@ req.end('Jane'); | |||
| 1803 | 1803 | ||
| 1804 | 1804 | ## Compatibility API | |
| 1805 | 1805 | ||
| 1806 | - The Compatibility API has the goal of providing a similar developer experience of | ||
| 1807 | - HTTP/1 when using HTTP/2, making it possible to develop applications | ||
| 1808 | - that supports both [HTTP/1](HTTP/1) and HTTP/2. This API targets only the **public | ||
| 1809 | - API** of the [HTTP/1](HTTP/1), however many modules uses internal | ||
| 1806 | + The Compatibility API has the goal of providing a similar developer experience | ||
| 1807 | + of HTTP/1 when using HTTP/2, making it possible to develop applications | ||
| 1808 | + that supports both [HTTP/1](HTTP/1) and HTTP/2. This API targets only the | ||
| 1809 | + **public API** of the [HTTP/1](HTTP/1), however many modules uses internal | ||
| 1810 | 1810 | methods or state, and those _are not supported_ as it is a completely | |
| 1811 | 1811 | different implementation. | |
| 1812 | 1812 | ||
@@ -1823,7 +1823,7 @@ const server = http2.createServer((req, res) => { | |||
| 1823 | 1823 | }); | |
| 1824 | 1824 | ``` | |
| 1825 | 1825 | ||
| 1826 | - In order to create a mixed [HTTPs](https) and HTTP/2 server, refer to the | ||
| 1826 | + In order to create a mixed [HTTPS](https) and HTTP/2 server, refer to the | ||
| 1827 | 1827 | [ALPN negotiation](alpn-negotiation) section. | |
| 1828 | 1828 | Upgrading from non-tls HTTP/1 servers is not supported. | |
| 1829 | 1829 | ||
@@ -1834,8 +1834,8 @@ the status message for HTTP codes is ignored. | |||
| 1834 | 1834 | ||
| 1835 | 1835 | ### ALPN negotiation | |
| 1836 | 1836 | ||
| 1837 | - ALPN negotiation allows to support both [HTTPs](https) and HTTP/2 over | ||
| 1838 | - the same socket. the `req` and `res` object could be either HTTP/1 or | ||
| 1837 | + ALPN negotiation allows to support both [HTTPS](https) and HTTP/2 over | ||
| 1838 | + the same socket. The `req` and `res` objects can be either HTTP/1 or | ||
| 1839 | 1839 | HTTP/2, and an application **must** restrict itself to the public API of | |
| 1840 | 1840 | [HTTP/1](), and detect if it is possible to use the more advanced | |
| 1841 | 1841 | features of HTTP/2. | |
@@ -1855,7 +1855,7 @@ const server = createSecureServer( | |||
| 1855 | 1855 | ).listen(4443); | |
| 1856 | 1856 | ||
| 1857 | 1857 | function onRequest(req, res) { | |
| 1858 | - // detects if it is a HTTPs request or HTTP/2 | ||
| 1858 | + // detects if it is a HTTPS request or HTTP/2 | ||
| 1859 | 1859 | const { socket: { alpnProtocol } } = request.httpVersion === '2.0' ? | |
| 1860 | 1860 | request.stream.session : request; | |
| 1861 | 1861 | response.writeHead(200, { 'content-type': 'application/json' }); | |
@@ -1866,7 +1866,7 @@ function onRequest(req, res) { | |||
| 1866 | 1866 | } | |
| 1867 | 1867 | ``` | |
| 1868 | 1868 | ||
| 1869 | - The `'request'` event works identically on both [HTTPs](https) and | ||
| 1869 | + The `'request'` event works identically on both [HTTPS](https) and | ||
| 1870 | 1870 | HTTP/2. | |
| 1871 | 1871 | ||
| 1872 | 1872 | ### Class: http2.Http2ServerRequest | |
@@ -1875,8 +1875,9 @@ added: REPLACEME | |||
| 1875 | 1875 | --> | |
| 1876 | 1876 | ||
| 1877 | 1877 | A `Http2ServerRequest` object is created by [`http2.Server`][] or | |
| 1878 | - [`http2.SecureServer`][] and passed as the first argument to the [`'request'`][] event. It may be used to access a request status, | ||
| 1879 | - headers and data. | ||
| 1878 | + [`http2.SecureServer`][] and passed as the first argument to the | ||
| 1879 | + [`'request'`][] event. It may be used to access a request status, headers and | ||
| 1880 | + data. | ||
| 1880 | 1881 | ||
| 1881 | 1882 | It implements the [Readable Stream][] interface, as well as the | |
| 1882 | 1883 | following additional events, methods, and properties. | |
@@ -1907,9 +1908,9 @@ added: REPLACEME | |||
| 1907 | 1908 | ||
| 1908 | 1909 | * `error` {Error} | |
| 1909 | 1910 | ||
| 1910 | - Calls `destroy()` on the [Http2Stream]() that received the `ServerRequest`. If `error` | ||
| 1911 | - is provided, an `'error'` event is emitted and `error` is passed as an argument | ||
| 1912 | - to any listeners on the event. | ||
| 1911 | + Calls `destroy()` on the [Http2Stream]() that received the `ServerRequest`. If | ||
| 1912 | + `error` is provided, an `'error'` event is emitted and `error` is passed as an | ||
| 1913 | + argument to any listeners on the event. | ||
| 1913 | 1914 | ||
| 1914 | 1915 | It does nothing if the stream was already destroyed. | |
| 1915 | 1916 | ||
@@ -2201,7 +2202,7 @@ added: REPLACEME | |||
| 2201 | 2202 | * `name` {string} | |
| 2202 | 2203 | * Returns: {string} | |
| 2203 | 2204 | ||
| 2204 | - Reads out a header that's already been queued but not sent to the client. | ||
| 2205 | + Reads out a header that has already been queued but not sent to the client. | ||
| 2205 | 2206 | Note that the name is case insensitive. | |
| 2206 | 2207 | ||
| 2207 | 2208 | Example: | |
@@ -2291,7 +2292,7 @@ added: REPLACEME | |||
| 2291 | 2292 | ||
| 2292 | 2293 | * `name` {string} | |
| 2293 | 2294 | ||
| 2294 | - Removes a header that's queued for implicit sending. | ||
| 2295 | + Removes a header that has been queued for implicit sending. | ||
| 2295 | 2296 | ||
| 2296 | 2297 | Example: | |
| 2297 | 2298 | ||
@@ -2339,9 +2340,9 @@ response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']); | |||
| 2339 | 2340 | Attempting to set a header field name or value that contains invalid characters | |
| 2340 | 2341 | will result in a [`TypeError`][] being thrown. | |
| 2341 | 2342 | ||
| 2342 | - When headers have been set with [`response.setHeader()`][], they will be merged with | ||
| 2343 | - any headers passed to [`response.writeHead()`][], with the headers passed to | ||
| 2344 | - [`response.writeHead()`][] given precedence. | ||
| 2343 | + When headers have been set with [`response.setHeader()`][], they will be merged | ||
| 2344 | + with any headers passed to [`response.writeHead()`][], with the headers passed | ||
| 2345 | + to [`response.writeHead()`][] given precedence. | ||
| 2345 | 2346 | ||
| 2346 | 2347 | ```js | |
| 2347 | 2348 | // returns content-type = text/plain | |
@@ -2366,9 +2367,9 @@ provided, then it is added as a listener on the `'timeout'` event on | |||
| 2366 | 2367 | the response object. | |
| 2367 | 2368 | ||
| 2368 | 2369 | If no `'timeout'` listener is added to the request, the response, or | |
| 2369 | - the server, then [`Http2Stream`]()s are destroyed when they time out. If a handler is | ||
| 2370 | - assigned to the request, the response, or the server's `'timeout'` events, | ||
| 2371 | - timed out sockets must be handled explicitly. | ||
| 2370 | + the server, then [`Http2Stream`]()s are destroyed when they time out. If a | ||
| 2371 | + handler is assigned to the request, the response, or the server's `'timeout'` | ||
| 2372 | + events, timed out sockets must be handled explicitly. | ||
| 2372 | 2373 | ||
| 2373 | 2374 | Returns `response`. | |
| 2374 | 2375 | ||
@@ -2478,7 +2479,8 @@ buffer. Returns `false` if all or part of the data was queued in user memory. | |||
| 2478 | 2479 | added: REPLACEME | |
| 2479 | 2480 | --> | |
| 2480 | 2481 | ||
| 2481 | - Throws an error as the `'continue'` flow is not current implemented. Added for parity with [HTTP/1](). | ||
| 2482 | + Throws an error as the `'continue'` flow is not current implemented. Added for | ||
| 2483 | + parity with [HTTP/1](). | ||
| 2482 | 2484 | ||
| 2483 | 2485 | ### response.writeHead(statusCode[, statusMessage][, headers]) | |
| 2484 | 2486 | <!-- YAML | |
@@ -2491,7 +2493,11 @@ added: REPLACEME | |||
| 2491 | 2493 | ||
| 2492 | 2494 | Sends a response header to the request. The status code is a 3-digit HTTP | |
| 2493 | 2495 | status code, like `404`. The last argument, `headers`, are the response headers. | |
| 2494 | - For compatibility with [HTTP/1](), one can give a human-readable `statusMessage` as the second argument, which will be silenty ignored and emit a warning. | ||
| 2496 | + | ||
| 2497 | + For compatibility with [HTTP/1](), a human-readable `statusMessage` may be | ||
| 2498 | + passed as the second argument. However, because the `statusMessage` has no | ||
| 2499 | + meaning within HTTP/2, the argument will have no effect and a process warning | ||
| 2500 | + will be emitted. | ||
| 2495 | 2501 | ||
| 2496 | 2502 | Example: | |
| 2497 | 2503 | ||
@@ -2502,15 +2508,22 @@ response.writeHead(200, { | |||
| 2502 | 2508 | 'Content-Type': 'text/plain' }); | |
| 2503 | 2509 | ``` | |
| 2504 | 2510 | ||
| 2505 | - This method must only be called once on a message and it must | ||
| 2506 | - be called before [`response.end()`][] is called. | ||
| 2511 | + Note that Content-Length is given in bytes not characters. The | ||
| 2512 | + `Buffer.byteLength()` API may be used to determine the number of bytes in a | ||
| 2513 | + given encoding. On outbound messages, Node.js does not check if Content-Length | ||
| 2514 | + and the length of the body being transmitted are equal or not. However, when | ||
| 2515 | + receiving messages, Node.js will automatically reject messages when the | ||
| 2516 | + Content-Length does not match the actual payload size. | ||
| 2517 | + | ||
| 2518 | + This method may be called at most one time on a message before | ||
| 2519 | + [`response.end()`][] is called. | ||
| 2507 | 2520 | ||
| 2508 | 2521 | If [`response.write()`][] or [`response.end()`][] are called before calling | |
| 2509 | 2522 | this, the implicit/mutable headers will be calculated and call this function. | |
| 2510 | 2523 | ||
| 2511 | - When headers have been set with [`response.setHeader()`][], they will be merged with | ||
| 2512 | - any headers passed to [`response.writeHead()`][], with the headers passed to | ||
| 2513 | - [`response.writeHead()`][] given precedence. | ||
| 2524 | + When headers have been set with [`response.setHeader()`][], they will be merged | ||
| 2525 | + with any headers passed to [`response.writeHead()`][], with the headers passed | ||
| 2526 | + to [`response.writeHead()`][] given precedence. | ||
| 2514 | 2527 | ||
| 2515 | 2528 | ```js | |
| 2516 | 2529 | // returns content-type = text/plain | |
@@ -2522,13 +2535,6 @@ const server = http2.createServer((req, res) => { | |||
| 2522 | 2535 | }); | |
| 2523 | 2536 | ``` | |
| 2524 | 2537 | ||
| 2525 | - Note that Content-Length is given in bytes not characters. The above example | ||
| 2526 | - works because the string `'hello world'` contains only single byte characters. | ||
| 2527 | - If the body contains higher coded characters then `Buffer.byteLength()` | ||
| 2528 | - should be used to determine the number of bytes in a given encoding. | ||
| 2529 | - And Node.js does not check whether Content-Length and the length of the body | ||
| 2530 | - which has been transmitted are equal or not. | ||
| 2531 | - | ||
| 2532 | 2538 | Attempting to set a header field name or value that contains invalid characters | |
| 2533 | 2539 | will result in a [`TypeError`][] being thrown. | |
| 2534 | 2540 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments