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
0d7c955b
Unverified
Commit
0d7c955b
authored
Nov 01, 2019
by
Kenton Varda
Committed by
GitHub
Nov 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #905 from capnproto/jlee/http-client-adapter-exceptions
Make HttpClient adapter preserve exception behavior
parents
3f73dc7f
ea4dc7f0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
17 deletions
+47
-17
http-test.c++
c++/src/kj/compat/http-test.c++
+33
-0
http.c++
c++/src/kj/compat/http.c++
+14
-17
No files found.
c++/src/kj/compat/http-test.c++
View file @
0d7c955b
...
...
@@ -3032,6 +3032,39 @@ KJ_TEST("newHttpClient from HttpService WebSockets") {
testWebSocketClient
(
waitScope
,
*
headerTable
,
hMyHeader
,
*
client
);
}
KJ_TEST
(
"adapted client/server propagates request exceptions like non-adapted client"
)
{
auto
io
=
kj
::
setupAsyncIo
();
HttpHeaderTable
table
;
HttpHeaders
headers
(
table
);
class
FailingHttpClient
final
:
public
HttpClient
{
public
:
Request
request
(
HttpMethod
method
,
kj
::
StringPtr
url
,
const
HttpHeaders
&
headers
,
kj
::
Maybe
<
uint64_t
>
expectedBodySize
=
nullptr
)
override
{
KJ_FAIL_ASSERT
(
"request_fail"
);
}
kj
::
Promise
<
WebSocketResponse
>
openWebSocket
(
kj
::
StringPtr
url
,
const
HttpHeaders
&
headers
)
override
{
KJ_FAIL_ASSERT
(
"websocket_fail"
);
}
};
auto
rawClient
=
kj
::
heap
<
FailingHttpClient
>
();
auto
innerClient
=
kj
::
heap
<
FailingHttpClient
>
();
auto
adaptedService
=
kj
::
newHttpService
(
*
innerClient
).
attach
(
kj
::
mv
(
innerClient
));
auto
adaptedClient
=
kj
::
newHttpClient
(
*
adaptedService
).
attach
(
kj
::
mv
(
adaptedService
));
KJ_EXPECT_THROW_MESSAGE
(
"request_fail"
,
rawClient
->
request
(
HttpMethod
::
POST
,
"/"
_kj
,
headers
));
KJ_EXPECT_THROW_MESSAGE
(
"request_fail"
,
adaptedClient
->
request
(
HttpMethod
::
POST
,
"/"
_kj
,
headers
));
KJ_EXPECT_THROW_MESSAGE
(
"websocket_fail"
,
rawClient
->
openWebSocket
(
"/"
_kj
,
headers
));
KJ_EXPECT_THROW_MESSAGE
(
"websocket_fail"
,
adaptedClient
->
openWebSocket
(
"/"
_kj
,
headers
));
}
// -----------------------------------------------------------------------------
class
CountingIoStream
final
:
public
kj
::
AsyncIoStream
{
...
...
c++/src/kj/compat/http.c++
View file @
0d7c955b
...
...
@@ -4294,15 +4294,13 @@ public:
// involving a PromiseAdapter, maybe?
auto
paf
=
kj
::
newPromiseAndFulfiller
<
Response
>
();
auto
responder
=
kj
::
refcounted
<
ResponseImpl
>
(
method
,
kj
::
mv
(
paf
.
fulfiller
));
auto
promise
=
kj
::
evalLater
([
this
,
method
,
urlCopy
=
kj
::
mv
(
urlCopy
),
headersCopy
=
kj
::
mv
(
headersCopy
),
pipeIn
=
kj
::
mv
(
pipe
.
in
),
&
responder
=
*
responder
]()
mutable
{
auto
promise
=
service
.
request
(
method
,
urlCopy
,
*
headersCopy
,
*
pipeIn
,
responder
);
return
promise
.
attach
(
kj
::
mv
(
pipeIn
),
kj
::
mv
(
urlCopy
),
kj
::
mv
(
headersCopy
));
});
responder
->
setPromise
(
kj
::
mv
(
promise
));
auto
requestPaf
=
kj
::
newPromiseAndFulfiller
<
kj
::
Promise
<
void
>>
();
responder
->
setPromise
(
kj
::
mv
(
requestPaf
.
promise
));
auto
promise
=
service
.
request
(
method
,
urlCopy
,
*
headersCopy
,
*
pipe
.
in
,
*
responder
)
.
attach
(
kj
::
mv
(
pipe
.
in
),
kj
::
mv
(
urlCopy
),
kj
::
mv
(
headersCopy
));
requestPaf
.
fulfiller
->
fulfill
(
kj
::
mv
(
promise
));
return
{
kj
::
mv
(
pipe
.
out
),
...
...
@@ -4323,15 +4321,14 @@ public:
auto
paf
=
kj
::
newPromiseAndFulfiller
<
WebSocketResponse
>
();
auto
responder
=
kj
::
refcounted
<
WebSocketResponseImpl
>
(
kj
::
mv
(
paf
.
fulfiller
));
auto
promise
=
kj
::
evalLater
([
this
,
urlCopy
=
kj
::
mv
(
urlCopy
),
headersCopy
=
kj
::
mv
(
headersCopy
),
&
responder
=
*
responder
]()
mutable
{
auto
requestPaf
=
kj
::
newPromiseAndFulfiller
<
kj
::
Promise
<
void
>>
();
responder
->
setPromise
(
kj
::
mv
(
requestPaf
.
promise
));
auto
in
=
kj
::
heap
<
NullInputStream
>
();
auto
promise
=
service
.
request
(
HttpMethod
::
GET
,
urlCopy
,
*
headersCopy
,
*
in
,
responder
);
return
promise
.
attach
(
kj
::
mv
(
in
),
kj
::
mv
(
urlCopy
),
kj
::
mv
(
headersCopy
));
});
responder
->
setPromise
(
kj
::
mv
(
promise
));
auto
promise
=
service
.
request
(
HttpMethod
::
GET
,
urlCopy
,
*
headersCopy
,
*
in
,
*
responder
)
.
attach
(
kj
::
mv
(
in
),
kj
::
mv
(
urlCopy
),
kj
::
mv
(
headersCopy
));
requestPaf
.
fulfiller
->
fulfill
(
kj
::
mv
(
promise
));
return
paf
.
promise
.
attach
(
kj
::
mv
(
responder
));
}
...
...
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