-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce slightly allocations when reading/writing HTTP messages (#950)
* Avoid creating additional string when writing headers * Define our own simpler Version type * Update src/Messages.jl Co-authored-by: Jacob Quinn <[email protected]> * Update src/Messages.jl Co-authored-by: Jacob Quinn <[email protected]> * Test we don't allocate * Tidy tests * Remove unused code * Update src/clientlayers/MessageRequest.jl * Write headers to temporary buffer first - ...before flushing to socket, to avoid task switching mid writing to the socket itself. * Remove unneeded temp buffer in Stream startwrite * Make loopback test less flaky by using Event instead of sleep * Don't connect a socket for Loopback test - unnecessary and was leading to occasional DNS Errors Co-authored-by: Jacob Quinn <[email protected]>
- Loading branch information
1 parent
7a54ffc
commit a2da061
Showing
11 changed files
with
158 additions
and
45 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
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
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,31 @@ | ||
@testset "HTTPVersion" begin | ||
|
||
# Constructors | ||
@test HTTPVersion(1) == HTTPVersion(1, 0) | ||
@test HTTPVersion(1) == HTTPVersion("1") | ||
@test HTTPVersion(1) == HTTPVersion("1.0") | ||
@test HTTPVersion(1) == HTTPVersion(v"1") | ||
@test HTTPVersion(1) == HTTPVersion(v"1.0") | ||
|
||
@test HTTPVersion(1, 1) == HTTPVersion("1.1") | ||
@test HTTPVersion(1, 1) == HTTPVersion(v"1.1") | ||
@test HTTPVersion(1, 1) == HTTPVersion(v"1.1.0") | ||
|
||
@test VersionNumber(HTTPVersion(1)) == v"1" | ||
@test VersionNumber(HTTPVersion(1, 1)) == v"1.1" | ||
|
||
# Important that we can parse a string into a `HTTPVersion` without allocations, | ||
# as we do this for every request/response. Similarly if we then want a `VersionNumber`. | ||
@test @allocated(HTTPVersion("1.1")) == 0 | ||
@test @allocated(VersionNumber(HTTPVersion("1.1"))) == 0 | ||
|
||
# Test comparisons with `VersionNumber`s | ||
req = HTTP.Request("GET", "http://httpbin.org/anything") | ||
res = HTTP.Response(200) | ||
for r in (req, res) | ||
@test r.version == v"1.1" | ||
@test r.version <= v"1.1" | ||
@test r.version < v"1.2" | ||
end | ||
|
||
end # testset |
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
Oops, something went wrong.