-
Notifications
You must be signed in to change notification settings - Fork 350
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
proxy: set zero content length for default response #2459
Conversation
|
||
assert.Equal(t, http.StatusNotFound, rsp.StatusCode) | ||
assert.Len(t, body, 0) | ||
assert.Equal(t, "0", rsp.Header.Get("Content-Length")) |
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 is an indirect test. It is hard to test that response is not chunked because http client handles chunked encoding transparently. To test it we would need to create net connection and send/receive raw HTTP request and response.
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.
I don't mind, but sounds simple enough to do:
GET / HTTP/1.1\r\n
Host: test\r\n
\r\n
d774ac2
to
ef1200f
Compare
👍 |
Content-Length header prevents http.ResponseWriter from writing chunked response. It turns out that reading empty chunked response is slow(er). In particular this change speeds up TrafficSegment tests that perform 10k requests to routes that send no body: ``` r50: Path("/test") && TrafficSegment(0.0, 0.5) -> status(200) -> <shunt>; r30: Path("/test") && TrafficSegment(0.5, 0.8) -> status(201) -> <shunt>; r20: Path("/test") && TrafficSegment(0.8, 1.0) -> status(202) -> <shunt>; ``` Test runtime before the change: ``` $ go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 9.357s ``` and after: ``` ok github.com/zalando/skipper/predicates/traffic 4.260s ``` Related #1562 Signed-off-by: Alexander Yastrebov <[email protected]>
ef1200f
to
4fbc3b5
Compare
@AlexanderYastrebov I think it does not comply with https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length , see for example by status code "MUST NOT". |
@szuecs Could you quote the part you mean? |
And then there are other conditions, for example:
[1] A sender MUST NOT send a Content-Length header field in any message that contains a Transfer-Encoding header field. |
Ok, but this sets |
Maybe it is not worth the effort. |
Add `inlineContent("")` to test routes to have `Content-Length: 0` response header that disables chunked encoding and speeds up the tests. Before: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 8.928s ``` After: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 4.285s ``` To further speedup make test requests in parallel: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 1.554s ``` See related #2459 #1562 Signed-off-by: Alexander Yastrebov <[email protected]>
TrafficSegment tests perform 10k test requests per test case. Add `inlineContent("")` to test routes to have `Content-Length: 0` response header that disables chunked encoding and speeds up the tests. Before: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 8.928s ``` After: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 4.285s ``` To further speedup make test requests in parallel: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 1.554s ``` See related #2459 #1562 Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov maybe the cases are also fine. Maybe you are right 😉 |
TrafficSegment tests perform 10k test requests per test case. Add `inlineContent("")` to test routes to have `Content-Length: 0` response header that disables chunked encoding and speeds up the tests. Before: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 8.928s ``` After: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 4.285s ``` To further speedup make test requests in parallel: ``` go test ./predicates/traffic/ -count=1 -run=TestTrafficSegment ok github.com/zalando/skipper/predicates/traffic 1.554s ``` See related #2459 #1562 Signed-off-by: Alexander Yastrebov <[email protected]>
Content-Length header prevents http.ResponseWriter from writing chunked response.
It turns out that reading empty chunked response is slow(er). In particular this change speeds up TrafficSegment tests that perform 10k requests to routes that send no body:
Test runtime before the change:
and after:
Related #1562