-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proxy: set zero content length for default response
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]>
- Loading branch information
1 parent
2936f25
commit 4fbc3b5
Showing
3 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package proxy_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/zalando/skipper/eskip" | ||
"github.com/zalando/skipper/proxy/proxytest" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaultResponse(t *testing.T) { | ||
p := proxytest.Config{ | ||
Routes: eskip.MustParse(`* -> <shunt>`), | ||
}.Create() | ||
defer p.Close() | ||
|
||
rsp, body, err := p.Client().GetBody(p.URL) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusNotFound, rsp.StatusCode) | ||
assert.Len(t, body, 0) | ||
assert.Equal(t, "0", rsp.Header.Get("Content-Length")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters