Skip to content

Commit 3b0f0b7

Browse files
authored
Take string view in mime methods (#12167)
* Take string_view in MIMEField::name_set * Take string_view in MIMEField::value_set * Take string_view in MIMEField::value_append * Take string_view in MIMEField::value_get_index * Take optional<string_view> in MIMEHdr::field_create * Take string_view in MIMEHdr::field_create * Take string_view in MIMEHdr::field_find * Take string_view in MIMEHdr::field_delete * Take string_view in MIMEHdr::value_get_index * Delete const char * version of MIMEHdr::value_get * Take string_view in MIMEHdr::value_get * Take string_view in MIMEHdr::value_get_int * Take string_view in MIMEHdr::value_get_uint * Take string_view in MIMEHdr::value_get_int64 * Take string_view in MIMEHdr::value_get_date * Take string_view in MIMEHdr::value_get_comma_list * Take string_view in MIMEHdr::value_set * Take string_view in MIMEHdr::value_set_int * Take string_view in MIMEHdr::value_set_uint * Take string_view in MIMEHdr::value_set_int64 * Take string_view in MIMEHdr::value_set_date * Take string_view in MIMEHdr::value_append * Take string_view in MIMEHdr::field_value_replace * Take string_view in MIMEHdr::field_value_set * Take string_view in MIMEHdr::field_value_append * Take string_view in MIMEHdr::value_append_or_set * Take string_view in MIMEHdr::set_server * Return std::tuple<MIMEField *, std::string_view, std::string_view> from MIMEHdr::get_host_port_values * Add assert to avoid false-positive nullptr-deref from clang-analyzer * Add mime header name and value "constants" MIME_{FIELD,VALUE}_*_sv * Delete const char *MIME_FIELD_* and MIME_VALUE_* and MIME_LEN constants * Add c_str_view * Change type of MIME_FIELD_* and MIME_VALUE_* to c_str_view * Take string_view in mime_hdr_field_find * Take string_view in _mime_hdr_field_list_search_by_string * Take string_view in mime_field_create_named * Take string_view in mime_hdr_prepare_for_value_set * Take string_view in mime_field_name_set * Take string_view in mime_field_value_set_comma_val * Take string_view in mime_field_value_extend_comma_val * Take string_view in mime_field_value_insert_comma_val * Take string_view in mime_field_value_set * Take string_view in mime_field_name_value_set * Take string_view in mime_field_value_append * Take string_view in mime_mem_print{,_lc} * Take string_view in mime_str_u16_set * Take string_view in mime_mem_print_ * Improve implementation of c_str_view * Add comment to c_str_view for its purpose and temporary use
1 parent 0868475 commit 3b0f0b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1599
-1817
lines changed

include/proxy/hdrs/HTTP.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#pragma once
2525

2626
#include <cassert>
27+
#include <string_view>
28+
29+
using namespace std::literals;
30+
2731
#include "tscore/Arena.h"
2832
#include "tscore/CryptoHash.h"
2933
#include "tscore/HTTPVersion.h"
@@ -869,9 +873,9 @@ is_header_keep_alive(const HTTPVersion &http_version, const MIMEField *con_hdr)
869873
// *unknown_tokens = false;
870874

871875
if (con_hdr) {
872-
if (con_hdr->value_get_index("keep-alive", 10) >= 0)
876+
if (con_hdr->value_get_index("keep-alive"sv) >= 0)
873877
con_token = CON_TOKEN_KEEP_ALIVE;
874-
else if (con_hdr->value_get_index("close", 5) >= 0)
878+
else if (con_hdr->value_get_index("close"sv) >= 0)
875879
con_token = CON_TOKEN_CLOSE;
876880
}
877881

@@ -895,11 +899,11 @@ inline HTTPKeepAlive
895899
HTTPHdr::keep_alive_get() const
896900
{
897901
HTTPKeepAlive retval = HTTP_NO_KEEPALIVE;
898-
const MIMEField *pc = this->field_find(MIME_FIELD_PROXY_CONNECTION, MIME_LEN_PROXY_CONNECTION);
902+
const MIMEField *pc = this->field_find(static_cast<std::string_view>(MIME_FIELD_PROXY_CONNECTION));
899903
if (pc != nullptr) {
900904
retval = is_header_keep_alive(this->version_get(), pc);
901905
} else {
902-
const MIMEField *c = this->field_find(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION);
906+
const MIMEField *c = this->field_find(static_cast<std::string_view>(MIME_FIELD_CONNECTION));
903907
retval = is_header_keep_alive(this->version_get(), c);
904908
}
905909
return retval;

include/proxy/hdrs/HdrToken.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "tscore/ink_assert.h"
2929
#include "tscore/ink_atomic.h"
3030
#include "tscore/ink_defs.h"
31+
#include "tscore/ink_memory.h"
3132
#include "tscore/ink_string.h"
3233
#include "tscore/Allocator.h"
3334
#include "tsutil/Regex.h"
@@ -107,6 +108,8 @@ extern int hdrtoken_tokenize(const char *string, int string_len, const c
107108
extern int hdrtoken_method_tokenize(const char *string, int string_len);
108109
extern const char *hdrtoken_string_to_wks(const char *string);
109110
extern const char *hdrtoken_string_to_wks(const char *string, int length);
111+
extern c_str_view hdrtoken_string_to_wks_sv(const char *string);
112+
extern c_str_view hdrtoken_string_to_wks_sv(const char *string, int length);
110113

111114
/*-------------------------------------------------------------------------
112115
-------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)