This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.2.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.2.x by this push: new 0d60f2f90 Add URLImpl::get_scheme (#9098) 0d60f2f90 is described below commit 0d60f2f90474af613c38bab9a4002ae0d93d6929 Author: Masakazu Kitajo <mas...@apache.org> AuthorDate: Tue Sep 20 16:56:22 2022 +0900 Add URLImpl::get_scheme (#9098) (cherry picked from commit dd0dfae435cbabe392a0d62d21e5c90b20cded19) --- proxy/hdrs/URL.cc | 15 +++++++++++++++ proxy/hdrs/URL.h | 11 ++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/proxy/hdrs/URL.cc b/proxy/hdrs/URL.cc index 2896cdfb9..c9b2f96d6 100644 --- a/proxy/hdrs/URL.cc +++ b/proxy/hdrs/URL.cc @@ -708,6 +708,21 @@ url_string_get_buf(URLImpl *url, char *dstbuf, int dstbuf_size, int *length) return buf; } +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +const char * +URLImpl::get_scheme(int *length) +{ + if (this->m_scheme_wks_idx >= 0) { + *length = hdrtoken_index_to_length(this->m_scheme_wks_idx); + return hdrtoken_index_to_wks(this->m_scheme_wks_idx); + } else { + *length = this->m_len_scheme; + return this->m_ptr_scheme; + } +} + /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ diff --git a/proxy/hdrs/URL.h b/proxy/hdrs/URL.h index c9a1c75f5..d91e9f1f8 100644 --- a/proxy/hdrs/URL.h +++ b/proxy/hdrs/URL.h @@ -82,6 +82,7 @@ public: // 8 bytes + 4 bits, will result in padding // Accessors + const char *get_scheme(int *length); const char *set_scheme(HdrHeap *heap, const char *value, int value_wks_idx, int length, bool copy_string); const char *get_user(int *length); void set_user(HdrHeap *heap, const char *value, int length, bool copy_string); @@ -514,13 +515,9 @@ inline const std::string_view URL::scheme_get() { ink_assert(valid()); - - if (m_url_impl->m_scheme_wks_idx >= 0) { - return std::string_view{hdrtoken_index_to_wks(m_url_impl->m_scheme_wks_idx), - static_cast<size_t>(hdrtoken_index_to_length(m_url_impl->m_scheme_wks_idx))}; - } else { - return std::string_view{m_url_impl->m_ptr_scheme, m_url_impl->m_len_scheme}; - } + int length; + const char *scheme = m_url_impl->get_scheme(&length); + return std::string_view{scheme, static_cast<size_t>(length)}; } inline const char *