Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
jsonrpsee
Commits
aa0936ab
Unverified
Commit
aa0936ab
authored
Jul 25, 2022
by
Alexandru Vasile
Browse files
http: Implement equivalent of `service_fn`
Signed-off-by:
Alexandru Vasile
<
alexandru.vasile@parity.io
>
parent
669a43be
Changes
1
Hide whitespace changes
Inline
Side-by-side
http-server/src/server.rs
View file @
aa0936ab
...
...
@@ -412,7 +412,10 @@ struct RPSeeSvcData<M> {
impl
<
M
:
Middleware
>
RPSeeSvcData
<
M
>
{
/// Default behavior for RPSee handling of requests.
pub
async
fn
handle_request
(
self
,
request
:
hyper
::
Request
<
hyper
::
Body
>
)
->
Result
<
hyper
::
Response
<
hyper
::
Body
>
,
HyperError
>
{
pub
async
fn
handle_request
(
self
,
request
:
hyper
::
Request
<
hyper
::
Body
>
,
)
->
Result
<
hyper
::
Response
<
hyper
::
Body
>
,
HyperError
>
{
let
RPSeeSvcData
{
remote_addr
,
methods
,
...
...
@@ -527,6 +530,30 @@ impl<M: Middleware> RPSeeSvcData<M> {
}
}
/// JsonRPSee service compatible with `tower`.
///
/// # Note
/// This is similar to [`hyper::service::service_fn`].
pub
struct
RPSeeServerSvc
<
M
>
{
inner
:
RPSeeSvcData
<
M
>
,
}
impl
<
M
:
Middleware
>
hyper
::
service
::
Service
<
hyper
::
Request
<
hyper
::
Body
>>
for
RPSeeServerSvc
<
M
>
{
type
Response
=
hyper
::
Response
<
hyper
::
Body
>
;
type
Error
=
hyper
::
Error
;
type
Future
=
Pin
<
Box
<
dyn
Future
<
Output
=
Result
<
Self
::
Response
,
Self
::
Error
>>
+
Send
>>
;
/// Opens door for back pressure implementation.
fn
poll_ready
(
&
mut
self
,
_
:
&
mut
Context
)
->
Poll
<
Result
<
(),
Self
::
Error
>>
{
Poll
::
Ready
(
Ok
(()))
}
fn
call
(
&
mut
self
,
request
:
hyper
::
Request
<
hyper
::
Body
>
)
->
Self
::
Future
{
let
data
=
self
.inner
.clone
();
Box
::
pin
(
data
.handle_request
(
request
))
}
}
/// An HTTP JSON RPC server.
#[derive(Debug)]
pub
struct
Server
<
M
=
()
>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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