8000 fix: Use vhost name instead of Host header in cache key calculation by MorganaFuture · Pull Request #2435 · tempesta-tech/tempesta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Use vhost name instead of Host header in cache key calculation #2435

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MorganaFuture
Copy link
Contributor
@MorganaFuture MorganaFuture commented Jun 3, 2025

What
Use vhost name instead of Host header in cache key calculation

Why
This change ensures proper cache operation when requests are redirected to different vhosts through HTTP chains.
Previously, the cache key was built using uri_path + host (from Host header), which caused incorrect cache behavior when a request with a Host header for one vhost was redirected to a different vhost via HTTP chains. This would lead to storing the cached response under a key that combined the URI with the original Host header, rather than the actual vhost that served the content.
With this change, the cache key is now correctly built using uri_path + vhost_name, ensuring that the cache operates properly even when HTTP chains redirect requests between different vhosts. The code falls back to using the Host header when a vhost is not yet assigned.

Links
2366

@MorganaFuture MorganaFuture force-pushed the MorganaFuture/fix/use_vhost_name_instead_of_host_header branch from 53e6a3f to 8fc689e Compare June 4, 2025 10:49
@MorganaFuture MorganaFuture marked this pull request as ready for review June 5, 2025 15:46
c = NULL; \
if (!(u_fin = WARN_ON_ONCE(TFW_STR_EMPTY(uri_path)))) { \
if (!(u_fin = WARN_ON_ONCE(TFW_STR_EMPTY(uri_path)))) { \
Copy link
Contributor

Choose a reason for hiding this comment

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

Broken \ aliment at the end of the string

memset(&vhost_empty, 0, sizeof(vhost_empty));
vhost_empty.name = empty_name;

TfwStr host_header = { .data = (void *)"some.host.com", .len = 13 };
Copy link
Contributor

Choose a reason for hiding this comment

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

All variables should be declared at the beginning of the function. ISO C90 forbids mixed declarations and code

TfwStr host_header = { .data = (void *)"some.host.com", .len = 13 };
test_req->host = host_header;

TfwStr uri_path = { .data = (void *)"/test", .len = 5 };
Copy link
Contributor

Choose a reason for hiding this comment

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

ISO C90 forbids mixed declarations and code

.data = (void *)"same.host.example.com",
.len = 21
};
test_req->host = host;
Copy link
Contributor

Choose a reason for hiding this comment

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

ISO C90 forbids mixed declarations and code

.data = (void *)"/test/path",
.len = 10
};
test_req->uri_path = uri_path;
Copy link
Contributor

Choose a reason for hiding this comment

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

ISO C90 forbids mixed declarations and code

key2 = tfw_http_req_key_calc(test_req);

/* Keys should be different because vhost names are different */
EXPECT_NE(key1, key2);
Copy link
Contributor

Choose a reason for hiding this comment

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

This expect fails, when I run this test.

@EvgeniiMekhanik
Copy link
Contributor

I also catch kernel warning at the string 2281 (cache.c) if (WARN_ON_ONCE(tot_len != 0))

@EvgeniiMekhanik
Copy link
Contributor

I also create brunch and add test. We should always write python tests.

Copy link
Contributor
@EvgeniiMekhanik EvgeniiMekhanik left a comment

Choose a reason for hiding this comment

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

Need to rework

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

Successfully merging this pull request may close these issues.

2 participants
0