-
Notifications
You must be signed in to change notification settings - Fork 106
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
base: master
Are you sure you want to change the base?
fix: Use vhost name instead of Host header in cache key calculation #2435
Conversation
53e6a3f
to
8fc689e
Compare
c = NULL; \ | ||
if (!(u_fin = WARN_ON_ONCE(TFW_STR_EMPTY(uri_path)))) { \ | ||
|
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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
fw/t/unit/test_http_cache.c
8000
div>
TfwStr host_header = { .data = (void *)"some.host.com", .len = 13 };
test_req->host = host_header;
TfwStr uri_path = { .data = (void *)"/test", .len = 5 };
There was a problem hiding this comment.
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
TfwStr host_header = { .data = (void *)"some.host.com", .len = 13 }; | ||
test_req->host = host_header; | ||
|
||
TfwStr uri_path = { .data = (void *)"/test", .len = 5 }; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
I also catch kernel warning at the string 2281 (cache.c) |
I also create brunch and add test. We should always write python tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to rework
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