Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Return string view from HTTPHdr methods #12091

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

hnakamur
Copy link
Contributor

@hnakamur hnakamur commented Mar 7, 2025

No description provided.

@hnakamur hnakamur force-pushed the return_string_view_from_HTTPHdr_methods branch from 448ecec to 90a30ce Compare March 7, 2025 14:22
@cmcfarlen cmcfarlen added this to the 10.2.0 milestone Mar 10, 2025
@cmcfarlen cmcfarlen self-requested a review March 10, 2025 22:11
Copy link
Contributor

@cmcfarlen cmcfarlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few places that need to be addressed. Thanks!

memccpy(hname, vector.get(i)->request_get()->host_get(&hlen), 0, 500);
auto host{vector.get(i)->request_get()->host_get()};
hlen = static_cast<int>(host.length());
memccpy(hname, host.data(), 0, 500);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is concerning here since string_view.data() isn't necessarily null terminated, but this copy is looking for one. This should be memcpy or strncpy (but still add the termination). Ideally hname would also be a string_view, but I'd have to dig further to see if that is possible without more refactoring.

if (host_sni_policy == 2) {
swoc::bwprint(error_bw_buffer, "No SNI for TLS request: connecting to {} for host='{}', returning a 403",
t_state.client_info.dst_addr, std::string_view{host_name, static_cast<size_t>(host_len)});
t_state.client_info.dst_addr, host_name.data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should drop .data() for these fmt style prints. They support sv directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in efb8ee8

char const *ptr = t_state.hdr_info.server_request.host_get(&len);
zret.assign(ptr, len);
auto host{t_state.hdr_info.server_request.host_get()};
zret.assign(host.data(), static_cast<int>(host.length()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be: zret = t_state.hdr_info.server_request.host_get()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in 9e31e96


if (is_localhost(host, host_len)) {
if (is_localhost(host.data(), static_cast<int>(host.length()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_localhost could take a string_view instead. This is the only place it is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in 266bea6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one test failure in https://ci.trafficserver.apache.org/job/Github_Builds/job/ubuntu/5645/console

RPRINT HostDBProcessor: HostDBRecord hostname=127.0.0.1
RPRINT HostDBProcessor: hostdbinfo RR0 ip=127.0.0.1
RPRINT HostDBProcessor: HostDBTestRR: 0 outstanding 5 success 1 failure
    REGRESSION_RESULT HostDBProcessor:                          FAILED

However it is not reproduced on my Ubuntu machine. I ran the following commands:

cmake -B build --preset ci-ubuntu
cmake --build build -j -v
cmake --install build
/tmp/ats/bin/traffic_server -K -k -R 1

All tests passed.

RPRINT HostDBProcessor: HostDBRecord hostname=127.0.0.1                                                                                                                                                             RPRINT HostDBProcessor: hostdbinfo RR0 ip=127.0.0.1                                                                                                                                                                 RPRINT HostDBProcessor: HostDBTestRR: 0 outstanding 6 success 0 failure                                                                                                                                                 REGRESSION_RESULT HostDBProcessor:                          PASSED
...(snip)...
REGRESSION_TEST DONE: PASSED

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants