This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 01c530bb37 Change MIMEFieldWrapper name_get and value_get to return
string_view (#12074)
01c530bb37 is described below
commit 01c530bb370da14c1bcd3b63bf68f85ecdb02c5b
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Fri Mar 7 15:19:50 2025 +0900
Change MIMEFieldWrapper name_get and value_get to return string_view
(#12074)
---
include/proxy/http2/HPACK.h | 16 +++++-------
src/proxy/http2/HPACK.cc | 18 ++++++-------
.../http2/unit_tests/test_HpackIndexingTable.cc | 30 ++++++++++------------
3 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/include/proxy/http2/HPACK.h b/include/proxy/http2/HPACK.h
index ac0092c2e0..f6610b3cc6 100644
--- a/include/proxy/http2/HPACK.h
+++ b/include/proxy/http2/HPACK.h
@@ -83,20 +83,16 @@ public:
_field->value_set(_heap, _mh, value, value_len);
}
- const char *
- name_get(int *length) const
+ std::string_view
+ name_get() const
{
- auto name{_field->name_get()};
- *length = static_cast<int>(name.length());
- return name.data();
+ return _field->name_get();
}
- const char *
- value_get(int *length) const
+ std::string_view
+ value_get() const
{
- auto value{_field->value_get()};
- *length = static_cast<int>(value.length());
- return value.data();
+ return _field->value_get();
}
const MIMEField *
diff --git a/src/proxy/http2/HPACK.cc b/src/proxy/http2/HPACK.cc
index fba4ae289b..6413897f9e 100644
--- a/src/proxy/http2/HPACK.cc
+++ b/src/proxy/http2/HPACK.cc
@@ -553,12 +553,11 @@ decode_indexed_header_field(MIMEFieldWrapper &header,
const uint8_t *buf_start,
}
if (dbg_ctl_hpack_decode.on()) {
- int decoded_name_len;
- const char *decoded_name = header.name_get(&decoded_name_len);
- int decoded_value_len;
- const char *decoded_value = header.value_get(&decoded_value_len);
+ auto decoded_name{header.name_get()};
+ auto decoded_value{header.value_get()};
- Dbg(dbg_ctl_hpack_decode, "Decoded field: %.*s: %.*s", decoded_name_len,
decoded_name, decoded_value_len, decoded_value);
+ Dbg(dbg_ctl_hpack_decode, "Decoded field: %.*s: %.*s",
static_cast<int>(decoded_name.length()), decoded_name.data(),
+ static_cast<int>(decoded_value.length()), decoded_value.data());
}
return len;
@@ -644,12 +643,11 @@ decode_literal_header_field(MIMEFieldWrapper &header,
const uint8_t *buf_start,
// Print decoded header field
if (dbg_ctl_hpack_decode.on()) {
- int decoded_name_len;
- const char *decoded_name = header.name_get(&decoded_name_len);
- int decoded_value_len;
- const char *decoded_value = header.value_get(&decoded_value_len);
+ auto decoded_name{header.name_get()};
+ auto decoded_value{header.value_get()};
- Dbg(dbg_ctl_hpack_decode, "Decoded field: %.*s: %.*s", decoded_name_len,
decoded_name, decoded_value_len, decoded_value);
+ Dbg(dbg_ctl_hpack_decode, "Decoded field: %.*s: %.*s",
static_cast<int>(decoded_name.length()), decoded_name.data(),
+ static_cast<int>(decoded_value.length()), decoded_value.data());
}
if (has_http2_violation) {
diff --git a/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc
b/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc
index 306c681f12..241f3facaf 100644
--- a/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc
+++ b/src/proxy/http2/unit_tests/test_HpackIndexingTable.cc
@@ -93,15 +93,13 @@ TEST_CASE("HPACK low level APIs", "[hpack]")
int len = decode_indexed_header_field(header, i.encoded_field,
i.encoded_field + i.encoded_field_len, indexing_table);
REQUIRE(len == i.encoded_field_len);
- int name_len;
- const char *name = header.name_get(&name_len);
- REQUIRE(name_len > 0);
- REQUIRE(memcmp(name, i.raw_name, name_len) == 0);
-
- int actual_value_len;
- const char *actual_value = header.value_get(&actual_value_len);
- REQUIRE(actual_value_len > 0);
- REQUIRE(memcmp(actual_value, i.raw_value, actual_value_len) == 0);
+ auto name{header.name_get()};
+ REQUIRE(name.length() > 0);
+ REQUIRE(name == std::string_view{i.raw_name});
+
+ auto actual_value{header.value_get()};
+ REQUIRE(actual_value.length() > 0);
+ REQUIRE(actual_value == std::string_view{i.raw_value});
}
}
}
@@ -228,15 +226,13 @@ TEST_CASE("HPACK low level APIs", "[hpack]")
int len = decode_literal_header_field(header, i.encoded_field,
i.encoded_field + i.encoded_field_len, indexing_table);
REQUIRE(len == i.encoded_field_len);
- int name_len;
- const char *name = header.name_get(&name_len);
- REQUIRE(name_len > 0);
- REQUIRE(memcmp(name, i.raw_name, name_len) == 0);
+ auto name{header.name_get()};
+ REQUIRE(name.length() > 0);
+ REQUIRE(name == std::string_view{i.raw_name});
- int actual_value_len;
- const char *actual_value = header.value_get(&actual_value_len);
- REQUIRE(actual_value_len > 0);
- REQUIRE(memcmp(actual_value, i.raw_value, actual_value_len) == 0);
+ auto actual_value{header.value_get()};
+ REQUIRE(actual_value.length() > 0);
+ REQUIRE(actual_value == std::string_view{i.raw_value});
}
}
}