This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit db47ab74b62d4efe7f93bc546f08f878f9aaf167 Author: David Calavera <[email protected]> AuthorDate: Tue Oct 29 09:30:24 2019 -0700 Change API to return a TSReturnCode code. Return a TS_ERROR when we cannot push the url to the promise table. Signed-off-by: David Calavera <[email protected]> (cherry picked from commit 4960789e3306dca7968a74ebd4f9eba4d45e1d2a) --- .../api/functions/TSHttpTxnServerPush.en.rst | 5 ++- include/ts/ts.h | 2 +- proxy/http2/Http2ConnectionState.cc | 11 +++--- proxy/http2/Http2ConnectionState.h | 2 +- proxy/http2/Http2Stream.cc | 4 +-- proxy/http2/Http2Stream.h | 2 +- src/traffic_server/InkAPI.cc | 41 ++++++++++++++-------- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/doc/developer-guide/api/functions/TSHttpTxnServerPush.en.rst b/doc/developer-guide/api/functions/TSHttpTxnServerPush.en.rst index be9ba1d..0710a07 100644 --- a/doc/developer-guide/api/functions/TSHttpTxnServerPush.en.rst +++ b/doc/developer-guide/api/functions/TSHttpTxnServerPush.en.rst @@ -28,7 +28,7 @@ Synopsis #include <ts/ts.h> -.. function:: void TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len) +.. function:: TSReturnCode TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len) Description =========== @@ -40,6 +40,9 @@ is not disabled by the client. You can call this API without checking whether Server Push is available on the transaction and it does nothing if Server Push is not available. +This API returns an error if the URL to push is not valid, the client has Server Push disabled, +or there is an error creating the H/2 PUSH_PROMISE frame. + See Also ======== diff --git a/include/ts/ts.h b/include/ts/ts.h index 17748d4..79ad523 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -2542,7 +2542,7 @@ tsapi TSIOBufferReader TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp); * @param url the URL string to preload. * @param url_len the length of the URL string. */ -tsapi void TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len); +tsapi TSReturnCode TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len); #ifdef __cplusplus } diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 7fb41ce..b23e0a5 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -1639,7 +1639,7 @@ Http2ConnectionState::send_headers_frame(Http2Stream *stream) ats_free(buf); } -void +bool Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, const MIMEField *accept_encoding) { HTTPHdr h1_hdr, h2_hdr; @@ -1651,7 +1651,7 @@ Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, con uint8_t flags = 0x00; if (client_settings.get(HTTP2_SETTINGS_ENABLE_PUSH) == 0) { - return; + return false; } Http2StreamDebug(ua_session, stream->get_id(), "Send PUSH_PROMISE frame"); @@ -1681,14 +1681,14 @@ Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, con buf = static_cast<uint8_t *>(ats_malloc(buf_len)); if (buf == nullptr) { h2_hdr.destroy(); - return; + return false; } Http2ErrorCode result = http2_encode_header_blocks(&h2_hdr, buf, buf_len, &header_blocks_size, *(this->remote_hpack_handle), client_settings.get(HTTP2_SETTINGS_HEADER_TABLE_SIZE)); if (result != Http2ErrorCode::HTTP2_ERROR_NO_ERROR) { h2_hdr.destroy(); ats_free(buf); - return; + return false; } // Send a PUSH_PROMISE frame @@ -1736,7 +1736,7 @@ Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, con stream = this->create_stream(id, error); if (!stream) { h2_hdr.destroy(); - return; + return false; } SCOPED_MUTEX_LOCK(stream_lock, stream->mutex, this_ethread()); @@ -1759,6 +1759,7 @@ Http2ConnectionState::send_push_promise_frame(Http2Stream *stream, URL &url, con stream->send_request(*this); h2_hdr.destroy(); + return true; } void diff --git a/proxy/http2/Http2ConnectionState.h b/proxy/http2/Http2ConnectionState.h index 01c80cf..afd4385 100644 --- a/proxy/http2/Http2ConnectionState.h +++ b/proxy/http2/Http2ConnectionState.h @@ -247,7 +247,7 @@ public: void send_data_frames(Http2Stream *stream); Http2SendDataFrameResult send_a_data_frame(Http2Stream *stream, size_t &payload_length); void send_headers_frame(Http2Stream *stream); - void send_push_promise_frame(Http2Stream *stream, URL &url, const MIMEField *accept_encoding); + bool send_push_promise_frame(Http2Stream *stream, URL &url, const MIMEField *accept_encoding); void send_rst_stream_frame(Http2StreamId id, Http2ErrorCode ec); void send_settings_frame(const Http2ConnectionSettings &new_settings); void send_ping_frame(Http2StreamId id, uint8_t flag, const uint8_t *opaque_data); diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index 8d2d5c6..eb98c4c 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -683,12 +683,12 @@ Http2Stream::signal_write_event(bool call_update) } } -void +bool Http2Stream::push_promise(URL &url, const MIMEField *accept_encoding) { Http2ClientSession *h2_proxy_ssn = static_cast<Http2ClientSession *>(this->_proxy_ssn); SCOPED_MUTEX_LOCK(lock, h2_proxy_ssn->connection_state.mutex, this_ethread()); - h2_proxy_ssn->connection_state.send_push_promise_frame(this, url, accept_encoding); + return h2_proxy_ssn->connection_state.send_push_promise_frame(this, url, accept_encoding); } void diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h index 58baee6..6a522a8 100644 --- a/proxy/http2/Http2Stream.h +++ b/proxy/http2/Http2Stream.h @@ -75,7 +75,7 @@ public: void update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool send_update); void signal_write_event(bool call_update); void restart_sending(); - void push_promise(URL &url, const MIMEField *accept_encoding); + bool push_promise(URL &url, const MIMEField *accept_encoding); // Stream level window size ssize_t client_rwnd() const; diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index 1d9dea3..fb910e0 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -8026,7 +8026,7 @@ TSHttpTxnIsInternal(TSHttpTxn txnp) return TSHttpSsnIsInternal(TSHttpTxnSsnGet(txnp)); } -void +TSReturnCode TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); @@ -8035,26 +8035,37 @@ TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len) url_obj.create(nullptr); if (url_obj.parse(url, url_len) == PARSE_RESULT_ERROR) { url_obj.destroy(); - return; + return TS_ERROR; } HttpSM *sm = reinterpret_cast<HttpSM *>(txnp); Http2Stream *stream = dynamic_cast<Http2Stream *>(sm->ua_txn); - if (stream) { - Http2ClientSession *ua_session = static_cast<Http2ClientSession *>(stream->get_proxy_ssn()); - SCOPED_MUTEX_LOCK(lock, ua_session->mutex, this_ethread()); - if (!ua_session->connection_state.is_state_closed() && !ua_session->is_url_pushed(url, url_len)) { - HTTPHdr *hptr = &(sm->t_state.hdr_info.client_request); - TSMLoc obj = reinterpret_cast<TSMLoc>(hptr->m_http); - - MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj); - MIMEField *f = mime_hdr_field_find(mh, MIME_FIELD_ACCEPT_ENCODING, MIME_LEN_ACCEPT_ENCODING); - stream->push_promise(url_obj, f); - - ua_session->add_url_to_pushed_table(url, url_len); - } + if (stream == nullptr) { + url_obj.destroy(); + return TS_ERROR; + } + + Http2ClientSession *ua_session = static_cast<Http2ClientSession *>(stream->get_proxy_ssn()); + SCOPED_MUTEX_LOCK(lock, ua_session->mutex, this_ethread()); + if (ua_session->connection_state.is_state_closed() || ua_session->is_url_pushed(url, url_len)) { + url_obj.destroy(); + return TS_ERROR; } + + HTTPHdr *hptr = &(sm->t_state.hdr_info.client_request); + TSMLoc obj = reinterpret_cast<TSMLoc>(hptr->m_http); + + MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj); + MIMEField *f = mime_hdr_field_find(mh, MIME_FIELD_ACCEPT_ENCODING, MIME_LEN_ACCEPT_ENCODING); + if (!stream->push_promise(url_obj, f)) { + url_obj.destroy(); + return TS_ERROR; + } + + ua_session->add_url_to_pushed_table(url, url_len); + url_obj.destroy(); + return TS_SUCCESS; } TSReturnCode
