Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
59da69a2
Commit
59da69a2
authored
7 years ago
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug in HTTP client connection reuse.
parent
c047c831
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
http-test.c++
c++/src/kj/compat/http-test.c++
+6
-0
http.c++
c++/src/kj/compat/http.c++
+8
-2
No files found.
c++/src/kj/compat/http-test.c++
View file @
59da69a2
...
...
@@ -2619,6 +2619,12 @@ KJ_TEST("HttpClient connection management") {
.
wait
(
io
.
waitScope
);
KJ_EXPECT
(
count
==
0
);
// Connections where we didn't even wait for the response headers are not reused.
doRequest
().
wait
(
io
.
waitScope
);
KJ_EXPECT
(
count
==
1
);
client
->
request
(
HttpMethod
::
GET
,
kj
::
str
(
"/foo"
),
HttpHeaders
(
headerTable
));
KJ_EXPECT
(
count
==
0
);
// Connections where we failed to write the full request body are not reused.
doRequest
().
wait
(
io
.
waitScope
);
KJ_EXPECT
(
count
==
1
);
...
...
This diff is collapsed.
Click to expand it.
c++/src/kj/compat/http.c++
View file @
59da69a2
...
...
@@ -993,7 +993,7 @@ public:
}
bool
canReuse
()
{
return
!
broken
;
return
!
broken
&&
pendingMessageCount
==
0
;
}
// ---------------------------------------------------------------------------
...
...
@@ -1005,6 +1005,7 @@ public:
KJ_REQUIRE_NONNULL
(
onMessageDone
)
->
fulfill
();
onMessageDone
=
nullptr
;
--
pendingMessageCount
;
}
void
abortRead
()
{
...
...
@@ -1066,6 +1067,7 @@ public:
}
kj
::
Promise
<
kj
::
ArrayPtr
<
char
>>
readMessageHeaders
()
{
++
pendingMessageCount
;
auto
paf
=
kj
::
newPromiseAndFulfiller
<
void
>
();
auto
promise
=
messageReadQueue
...
...
@@ -1194,6 +1196,9 @@ private:
bool
broken
=
false
;
// Becomes true if the caller failed to read the whole entity-body before closing the stream.
uint
pendingMessageCount
=
0
;
// Number of reads we have queued up.
kj
::
Promise
<
void
>
messageReadQueue
=
kj
::
READY_NOW
;
kj
::
Maybe
<
kj
::
Own
<
kj
::
PromiseFulfiller
<
void
>>>
onMessageDone
;
...
...
@@ -2413,7 +2418,8 @@ public:
settings
(
kj
::
mv
(
settings
))
{}
bool
canReuse
()
{
// Returns true if we can reuse this HttpClient for another request.
// Returns true if we can immediately reuse this HttpClient for another message (so all
// previous messages have been fully read).
return
!
upgraded
&&
!
closed
&&
httpInput
.
canReuse
()
&&
httpOutput
.
canReuse
();
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment