| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,7 +126,10 @@ const { | |||
| 126 | 126 | HTTP_STATUS_OK, | |
| 127 | 127 | HTTP_STATUS_NO_CONTENT, | |
| 128 | 128 | HTTP_STATUS_NOT_MODIFIED, | |
| 129 | - HTTP_STATUS_SWITCHING_PROTOCOLS | ||
| 129 | + HTTP_STATUS_SWITCHING_PROTOCOLS, | ||
| 130 | + | ||
| 131 | + STREAM_OPTION_EMPTY_PAYLOAD, | ||
| 132 | + STREAM_OPTION_GET_TRAILERS | ||
| 130 | 133 | } = constants; | |
| 131 | 134 | ||
| 132 | 135 | // Top level to avoid creating a closure | |
@@ -411,20 +414,22 @@ function requestOnConnect(headers, options) { | |||
| 411 | 414 | return; | |
| 412 | 415 | } | |
| 413 | 416 | ||
| 414 | - let getTrailers = false; | ||
| 417 | + let streamOptions = 0; | ||
| 418 | + if (options.endStream) | ||
| 419 | + streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD; | ||
| 420 | + | ||
| 415 | 421 | if (typeof options.getTrailers === 'function') { | |
| 416 | - getTrailers = true; | ||
| 422 | + streamOptions |= STREAM_OPTION_GET_TRAILERS; | ||
| 417 | 423 | this[kState].getTrailers = options.getTrailers; | |
| 418 | 424 | } | |
| 419 | 425 | ||
| 420 | 426 | // ret will be either the reserved stream ID (if positive) | |
| 421 | 427 | // or an error code (if negative) | |
| 422 | 428 | const ret = handle.submitRequest(headersList, | |
| 423 | - !!options.endStream, | ||
| 429 | + streamOptions, | ||
| 424 | 430 | options.parent | 0, | |
| 425 | 431 | options.weight | 0, | |
| 426 | - !!options.exclusive, | ||
| 427 | - getTrailers); | ||
| 432 | + !!options.exclusive); | ||
| 428 | 433 | ||
| 429 | 434 | // In an error condition, one of three possible response codes will be | |
| 430 | 435 | // possible: | |
@@ -1567,7 +1572,7 @@ function processHeaders(headers) { | |||
| 1567 | 1572 | } | |
| 1568 | 1573 | ||
| 1569 | 1574 | function processRespondWithFD(fd, headers, offset = 0, length = -1, | |
| 1570 | - getTrailers = false) { | ||
| 1575 | + streamOptions = 0) { | ||
| 1571 | 1576 | const session = this[kSession]; | |
| 1572 | 1577 | const state = this[kState]; | |
| 1573 | 1578 | state.headersSent = true; | |
@@ -1577,7 +1582,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1, | |||
| 1577 | 1582 | ||
| 1578 | 1583 | const handle = session[kHandle]; | |
| 1579 | 1584 | const ret = | |
| 1580 | - handle.submitFile(this[kID], fd, headers, offset, length, getTrailers); | ||
| 1585 | + handle.submitFile(this[kID], fd, headers, offset, length, streamOptions); | ||
| 1581 | 1586 | let err; | |
| 1582 | 1587 | switch (ret) { | |
| 1583 | 1588 | case NGHTTP2_ERR_NOMEM: | |
@@ -1592,7 +1597,7 @@ function processRespondWithFD(fd, headers, offset = 0, length = -1, | |||
| 1592 | 1597 | } | |
| 1593 | 1598 | } | |
| 1594 | 1599 | ||
| 1595 | - function doSendFD(session, options, fd, headers, getTrailers, err, stat) { | ||
| 1600 | + function doSendFD(session, options, fd, headers, streamOptions, err, stat) { | ||
| 1596 | 1601 | if (this.destroyed || session.destroyed) { | |
| 1597 | 1602 | abort(this); | |
| 1598 | 1603 | return; | |
@@ -1622,10 +1627,10 @@ function doSendFD(session, options, fd, headers, getTrailers, err, stat) { | |||
| 1622 | 1627 | processRespondWithFD.call(this, fd, headersList, | |
| 1623 | 1628 | statOptions.offset, | |
| 1624 | 1629 | statOptions.length, | |
| 1625 | - getTrailers); | ||
| 1630 | + streamOptions); | ||
| 1626 | 1631 | } | |
| 1627 | 1632 | ||
| 1628 | - function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) { | ||
| 1633 | + function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) { | ||
| 1629 | 1634 | if (this.destroyed || session.destroyed) { | |
| 1630 | 1635 | abort(this); | |
| 1631 | 1636 | return; | |
@@ -1680,10 +1685,10 @@ function doSendFileFD(session, options, fd, headers, getTrailers, err, stat) { | |||
| 1680 | 1685 | processRespondWithFD.call(this, fd, headersList, | |
| 1681 | 1686 | options.offset, | |
| 1682 | 1687 | options.length, | |
| 1683 | - getTrailers); | ||
| 1688 | + streamOptions); | ||
| 1684 | 1689 | } | |
| 1685 | 1690 | ||
| 1686 | - function afterOpen(session, options, headers, getTrailers, err, fd) { | ||
| 1691 | + function afterOpen(session, options, headers, streamOptions, err, fd) { | ||
| 1687 | 1692 | const state = this[kState]; | |
| 1688 | 1693 | const onError = options.onError; | |
| 1689 | 1694 | if (this.destroyed || session.destroyed) { | |
@@ -1701,7 +1706,8 @@ function afterOpen(session, options, headers, getTrailers, err, fd) { | |||
| 1701 | 1706 | state.fd = fd; | |
| 1702 | 1707 | ||
| 1703 | 1708 | fs.fstat(fd, | |
| 1704 | - doSendFileFD.bind(this, session, options, fd, headers, getTrailers)); | ||
| 1709 | + doSendFileFD.bind(this, session, options, fd, | ||
| 1710 | + headers, streamOptions)); | ||
| 1705 | 1711 | } | |
| 1706 | 1712 | ||
| 1707 | 1713 | function streamOnError(err) { | |
@@ -1785,9 +1791,9 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1785 | 1791 | throw headersList; | |
| 1786 | 1792 | } | |
| 1787 | 1793 | ||
| 1788 | - const ret = handle.submitPushPromise(this[kID], | ||
| 1789 | - headersList, | ||
| 1790 | - options.endStream); | ||
| 1794 | + const streamOptions = options.endStream ? STREAM_OPTION_EMPTY_PAYLOAD : 0; | ||
| 1795 | + | ||
| 1796 | + const ret = handle.submitPushPromise(this[kID], headersList, streamOptions); | ||
| 1791 | 1797 | let err; | |
| 1792 | 1798 | switch (ret) { | |
| 1793 | 1799 | case NGHTTP2_ERR_NOMEM: | |
@@ -1843,14 +1849,17 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1843 | 1849 | options = Object.assign(Object.create(null), options); | |
| 1844 | 1850 | options.endStream = !!options.endStream; | |
| 1845 | 1851 | ||
| 1846 | - let getTrailers = false; | ||
| 1852 | + let streamOptions = 0; | ||
| 1853 | + if (options.endStream) | ||
| 1854 | + streamOptions |= STREAM_OPTION_EMPTY_PAYLOAD; | ||
| 1855 | + | ||
| 1847 | 1856 | if (options.getTrailers !== undefined) { | |
| 1848 | 1857 | if (typeof options.getTrailers !== 'function') { | |
| 1849 | 1858 | throw new errors.TypeError('ERR_INVALID_OPT_VALUE', | |
| 1850 | 1859 | 'getTrailers', | |
| 1851 | 1860 | options.getTrailers); | |
| 1852 | 1861 | } | |
| 1853 | - getTrailers = true; | ||
| 1862 | + streamOptions |= STREAM_OPTION_GET_TRAILERS; | ||
| 1854 | 1863 | state.getTrailers = options.getTrailers; | |
| 1855 | 1864 | } | |
| 1856 | 1865 | ||
@@ -1880,10 +1889,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1880 | 1889 | ||
| 1881 | 1890 | const handle = session[kHandle]; | |
| 1882 | 1891 | const ret = | |
| 1883 | - handle.submitResponse(this[kID], | ||
| 1884 | - headersList, | ||
| 1885 | - options.endStream, | ||
| 1886 | - getTrailers); | ||
| 1892 | + handle.submitResponse(this[kID], headersList, streamOptions); | ||
| 1887 | 1893 | let err; | |
| 1888 | 1894 | switch (ret) { | |
| 1889 | 1895 | case NGHTTP2_ERR_NOMEM: | |
@@ -1936,14 +1942,14 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1936 | 1942 | options.statCheck); | |
| 1937 | 1943 | } | |
| 1938 | 1944 | ||
| 1939 | - let getTrailers = false; | ||
| 1945 | + let streamOptions = 0; | ||
| 1940 | 1946 | if (options.getTrailers !== undefined) { | |
| 1941 | 1947 | if (typeof options.getTrailers !== 'function') { | |
| 1942 | 1948 | throw new errors.TypeError('ERR_INVALID_OPT_VALUE', | |
| 1943 | 1949 | 'getTrailers', | |
| 1944 | 1950 | options.getTrailers); | |
| 1945 | 1951 | } | |
| 1946 | - getTrailers = true; | ||
| 1952 | + streamOptions |= STREAM_OPTION_GET_TRAILERS; | ||
| 1947 | 1953 | state.getTrailers = options.getTrailers; | |
| 1948 | 1954 | } | |
| 1949 | 1955 | ||
@@ -1962,7 +1968,8 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1962 | 1968 | ||
| 1963 | 1969 | if (options.statCheck !== undefined) { | |
| 1964 | 1970 | fs.fstat(fd, | |
| 1965 | - doSendFD.bind(this, session, options, fd, headers, getTrailers)); | ||
| 1971 | + doSendFD.bind(this, session, options, fd, | ||
| 1972 | + headers, streamOptions)); | ||
| 1966 | 1973 | return; | |
| 1967 | 1974 | } | |
| 1968 | 1975 | ||
@@ -1976,7 +1983,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 1976 | 1983 | processRespondWithFD.call(this, fd, headersList, | |
| 1977 | 1984 | options.offset, | |
| 1978 | 1985 | options.length, | |
| 1979 | - getTrailers); | ||
| 1986 | + streamOptions); | ||
| 1980 | 1987 | } | |
| 1981 | 1988 | ||
| 1982 | 1989 | // Initiate a file response on this Http2Stream. The path is passed to | |
@@ -2018,14 +2025,14 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 2018 | 2025 | options.statCheck); | |
| 2019 | 2026 | } | |
| 2020 | 2027 | ||
| 2021 | - let getTrailers = false; | ||
| 2028 | + let streamOptions = 0; | ||
| 2022 | 2029 | if (options.getTrailers !== undefined) { | |
| 2023 | 2030 | if (typeof options.getTrailers !== 'function') { | |
| 2024 | 2031 | throw new errors.TypeError('ERR_INVALID_OPT_VALUE', | |
| 2025 | 2032 | 'getTrailers', | |
| 2026 | 2033 | options.getTrailers); | |
| 2027 | 2034 | } | |
| 2028 | - getTrailers = true; | ||
| 2035 | + streamOptions |= STREAM_OPTION_GET_TRAILERS; | ||
| 2029 | 2036 | state.getTrailers = options.getTrailers; | |
| 2030 | 2037 | } | |
| 2031 | 2038 | ||
@@ -2039,7 +2046,7 @@ class ServerHttp2Stream extends Http2Stream { | |||
| 2039 | 2046 | } | |
| 2040 | 2047 | ||
| 2041 | 2048 | fs.open(path, 'r', | |
| 2042 | - afterOpen.bind(this, session, options, headers, getTrailers)); | ||
| 2049 | + afterOpen.bind(this, session, options, headers, streamOptions)); | ||
| 2043 | 2050 | } | |
| 2044 | 2051 | ||
| 2045 | 2052 | // Sends a block of informational headers. In theory, the HTTP/2 spec | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -479,7 +479,7 @@ void Http2Session::SubmitRstStream(const FunctionCallbackInfo<Value>& args) { | |||
| 479 | 479 | ||
| 480 | 480 | void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) { | |
| 481 | 481 | // args[0] Array of headers | |
| 482 | - // args[1] endStream boolean | ||
| 482 | + // args[1] options int | ||
| 483 | 483 | // args[2] parentStream ID (for priority spec) | |
| 484 | 484 | // args[3] weight (for priority spec) | |
| 485 | 485 | // args[4] exclusive boolean (for priority spec) | |
@@ -492,15 +492,14 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) { | |||
| 492 | 492 | Isolate* isolate = env->isolate(); | |
| 493 | 493 | ||
| 494 | 494 | Local<Array> headers = args[0].As<Array>(); | |
| 495 | - bool endStream = args[1]->BooleanValue(context).ToChecked(); | ||
| 495 | + int options = args[1]->IntegerValue(context).ToChecked(); | ||
| 496 | 496 | int32_t parent = args[2]->Int32Value(context).ToChecked(); | |
| 497 | 497 | int32_t weight = args[3]->Int32Value(context).ToChecked(); | |
| 498 | 498 | bool exclusive = args[4]->BooleanValue(context).ToChecked(); | |
| 499 | - bool getTrailers = args[5]->BooleanValue(context).ToChecked(); | ||
| 500 | 499 | ||
| 501 | - DEBUG_HTTP2("Http2Session: submitting request: headers: %d, end-stream: %d, " | ||
| 500 | + DEBUG_HTTP2("Http2Session: submitting request: headers: %d, options: %d, " | ||
| 502 | 501 | "parent: %d, weight: %d, exclusive: %d\n", headers->Length(), | |
| 503 | - endStream, parent, weight, exclusive); | ||
| 502 | + options, parent, weight, exclusive); | ||
| 504 | 503 | ||
| 505 | 504 | nghttp2_priority_spec prispec; | |
| 506 | 505 | nghttp2_priority_spec_init(&prispec, parent, weight, exclusive ? 1 : 0); | |
@@ -509,8 +508,7 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) { | |||
| 509 | 508 | ||
| 510 | 509 | int32_t ret = session->Nghttp2Session::SubmitRequest(&prispec, | |
| 511 | 510 | *list, list.length(), | |
| 512 | - nullptr, endStream, | ||
| 513 | - getTrailers); | ||
| 511 | + nullptr, options); | ||
| 514 | 512 | DEBUG_HTTP2("Http2Session: request submitted, response: %d\n", ret); | |
| 515 | 513 | args.GetReturnValue().Set(ret); | |
| 516 | 514 | } | |
@@ -529,11 +527,10 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) { | |||
| 529 | 527 | ||
| 530 | 528 | int32_t id = args[0]->Int32Value(context).ToChecked(); | |
| 531 | 529 | Local<Array> headers = args[1].As<Array>(); | |
| 532 | - bool endStream = args[2]->BooleanValue(context).ToChecked(); | ||
| 533 | - bool getTrailers = args[3]->BooleanValue(context).ToChecked(); | ||
| 530 | + int options = args[2]->IntegerValue(context).ToChecked(); | ||
| 534 | 531 | ||
| 535 | 532 | DEBUG_HTTP2("Http2Session: submitting response for stream %d: headers: %d, " | |
| 536 | - "end-stream: %d\n", id, headers->Length(), endStream); | ||
| 533 | + "options: %d\n", id, headers->Length(), options); | ||
| 537 | 534 | ||
| 538 | 535 | if (!(stream = session->FindStream(id))) { | |
| 539 | 536 | return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID); | |
@@ -542,7 +539,7 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) { | |||
| 542 | 539 | Headers list(isolate, context, headers); | |
| 543 | 540 | ||
| 544 | 541 | args.GetReturnValue().Set( | |
| 545 | - stream->SubmitResponse(*list, list.length(), endStream, getTrailers)); | ||
| 542 | + stream->SubmitResponse(*list, list.length(), options)); | ||
| 546 | 543 | } | |
| 547 | 544 | ||
| 548 | 545 | void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) { | |
@@ -566,7 +563,7 @@ void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) { | |||
| 566 | 563 | ||
| 567 | 564 | int64_t offset = args[3]->IntegerValue(context).ToChecked(); | |
| 568 | 565 | int64_t length = args[4]->IntegerValue(context).ToChecked(); | |
| 569 | - bool getTrailers = args[5]->BooleanValue(context).ToChecked(); | ||
| 566 | + int options = args[5]->IntegerValue(context).ToChecked(); | ||
| 570 | 567 | ||
| 571 | 568 | CHECK_GE(offset, 0); | |
| 572 | 569 | ||
@@ -580,7 +577,7 @@ void Http2Session::SubmitFile(const FunctionCallbackInfo<Value>& args) { | |||
| 580 | 577 | Headers list(isolate, context, headers); | |
| 581 | 578 | ||
| 582 | 579 | args.GetReturnValue().Set(stream->SubmitFile(fd, *list, list.length(), | |
| 583 | - offset, length, getTrailers)); | ||
| 580 | + offset, length, options)); | ||
| 584 | 581 | } | |
| 585 | 582 | ||
| 586 | 583 | void Http2Session::SendHeaders(const FunctionCallbackInfo<Value>& args) { | |
@@ -719,10 +716,10 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) { | |||
| 719 | 716 | Nghttp2Stream* parent; | |
| 720 | 717 | int32_t id = args[0]->Int32Value(context).ToChecked(); | |
| 721 | 718 | Local<Array> headers = args[1].As<Array>(); | |
| 722 | - bool endStream = args[2]->BooleanValue(context).ToChecked(); | ||
| 719 | + int options = args[2]->IntegerValue(context).ToChecked(); | ||
| 723 | 720 | ||
| 724 | 721 | DEBUG_HTTP2("Http2Session: submitting push promise for stream %d: " | |
| 725 | - "end-stream: %d, headers: %d\n", id, endStream, | ||
| 722 | + "options: %d, headers: %d\n", id, options, | ||
| 726 | 723 | headers->Length()); | |
| 727 | 724 | ||
| 728 | 725 | if (!(parent = session->FindStream(id))) { | |
@@ -732,7 +729,7 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) { | |||
| 732 | 729 | Headers list(isolate, context, headers); | |
| 733 | 730 | ||
| 734 | 731 | int32_t ret = parent->SubmitPushPromise(*list, list.length(), | |
| 735 | - nullptr, endStream); | ||
| 732 | + nullptr, options); | ||
| 736 | 733 | DEBUG_HTTP2("Http2Session: push promise submitted, ret: %d\n", ret); | |
| 737 | 734 | args.GetReturnValue().Set(ret); | |
| 738 | 735 | } | |
@@ -1250,6 +1247,9 @@ void Initialize(Local<Object> target, | |||
| 1250 | 1247 | NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_ERR_STREAM_CLOSED); | |
| 1251 | 1248 | NODE_DEFINE_CONSTANT(constants, NGHTTP2_ERR_FRAME_SIZE_ERROR); | |
| 1252 | 1249 | ||
| 1250 | + NODE_DEFINE_HIDDEN_CONSTANT(constants, STREAM_OPTION_EMPTY_PAYLOAD); | ||
| 1251 | + NODE_DEFINE_HIDDEN_CONSTANT(constants, STREAM_OPTION_GET_TRAILERS); | ||
| 1252 | + | ||
| 1253 | 1253 | NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_NONE); | |
| 1254 | 1254 | NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_STREAM); | |
| 1255 | 1255 | NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLAG_END_HEADERS); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments