-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(httpclientx): allow configuring max-response-body size (#1588)
While removing `httpapi` in #1560, I noticed that I actually liked limiting the max body size, which is particularly useful in case of gzip bombs. So, add tests for gzip bombs and allow configuring the maximum body size. We detect truncation by reading one more byte than needed and then checking the body length. Part of ooni/probe#2729.
- Loading branch information
1 parent
0232df5
commit 7ab645d
Showing
5 changed files
with
166 additions
and
14 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
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,21 @@ | ||
package httpclientx | ||
|
||
import "testing" | ||
|
||
func TestConfigMaxResponseBodySize(t *testing.T) { | ||
t.Run("the default returned value corresponds to the constant default", func(t *testing.T) { | ||
config := &Config{} | ||
if value := config.maxResponseBodySize(); value != DefaultMaxResponseBodySize { | ||
t.Fatal("unexpected maxResponseBodySize()", value) | ||
} | ||
}) | ||
|
||
t.Run("we can override the default", func(t *testing.T) { | ||
config := &Config{} | ||
const expectedValue = DefaultMaxResponseBodySize / 2 | ||
config.MaxResponseBodySize = expectedValue | ||
if value := config.maxResponseBodySize(); value != expectedValue { | ||
t.Fatal("unexpected maxResponseBodySize()", value) | ||
} | ||
}) | ||
} |
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