@@ -54,9 +54,11 @@ use crate::web::*;
5454use mwc_chain:: { Chain , SyncState } ;
5555use mwc_core:: global;
5656use mwc_core:: stratum;
57+ use mwc_crates:: bytes:: Bytes ;
5758use mwc_crates:: easy_jsonrpc_mwc:: { Handler , MaybeReply } ;
59+ use mwc_crates:: http_body_util:: Full ;
5860use mwc_crates:: hyper;
59- use mwc_crates:: hyper:: { Body , Request , Response , StatusCode } ;
61+ use mwc_crates:: hyper:: { Request , Response , StatusCode } ;
6062use mwc_crates:: log:: { error, warn} ;
6163use mwc_crates:: serde:: Serialize ;
6264use mwc_crates:: serde_json;
@@ -238,7 +240,7 @@ impl OwnerAPIHandlerV2 {
238240}
239241
240242impl crate :: router:: Handler for OwnerAPIHandlerV2 {
241- fn post ( & self , req : Request < Body > ) -> ResponseFuture {
243+ fn post ( & self , req : Request < Bytes > ) -> ResponseFuture {
242244 let api = Owner :: new (
243245 self . chain . clone ( ) ,
244246 self . peers . clone ( ) ,
@@ -267,7 +269,7 @@ impl crate::router::Handler for OwnerAPIHandlerV2 {
267269 } )
268270 }
269271
270- fn options ( & self , _req : Request < Body > ) -> ResponseFuture {
272+ fn options ( & self , _req : Request < Bytes > ) -> ResponseFuture {
271273 Box :: pin ( async { Ok ( create_ok_response ( "{}" ) ) } )
272274 }
273275}
@@ -312,7 +314,7 @@ where
312314 B : BlockChain + ' static ,
313315 P : PoolAdapter + ' static ,
314316{
315- fn post ( & self , req : Request < Body > ) -> ResponseFuture {
317+ fn post ( & self , req : Request < Bytes > ) -> ResponseFuture {
316318 let api = Foreign :: new (
317319 self . peers . clone ( ) ,
318320 self . chain . clone ( ) ,
@@ -343,7 +345,7 @@ where
343345 } )
344346 }
345347
346- fn options ( & self , _req : Request < Body > ) -> ResponseFuture {
348+ fn options ( & self , _req : Request < Bytes > ) -> ResponseFuture {
347349 Box :: pin ( async { Ok ( create_ok_response ( "{}" ) ) } )
348350 }
349351}
@@ -361,7 +363,7 @@ impl StratumAPIHandlerV2 {
361363}
362364
363365impl crate :: router:: Handler for StratumAPIHandlerV2 {
364- fn post ( & self , req : Request < Body > ) -> ResponseFuture {
366+ fn post ( & self , req : Request < Bytes > ) -> ResponseFuture {
365367 let api = Stratum :: new ( self . stratum_ip_pool . clone ( ) ) ;
366368
367369 Box :: pin ( async move {
@@ -386,13 +388,13 @@ impl crate::router::Handler for StratumAPIHandlerV2 {
386388 } )
387389 }
388390
389- fn options ( & self , _req : Request < Body > ) -> ResponseFuture {
391+ fn options ( & self , _req : Request < Bytes > ) -> ResponseFuture {
390392 Box :: pin ( async { Ok ( create_ok_response ( "{}" ) ) } )
391393 }
392394}
393395
394396// pretty-printed version of above
395- fn json_response_pretty < T > ( s : & T ) -> Response < Body >
397+ fn json_response_pretty < T > ( s : & T ) -> Response < Full < Bytes > >
396398where
397399 T : Serialize ,
398400{
@@ -405,22 +407,22 @@ where
405407 }
406408}
407409
408- fn create_error_response ( e : Error ) -> Response < Body > {
410+ fn create_error_response ( e : Error ) -> Response < Full < Bytes > > {
409411 match Response :: builder ( )
410412 . status ( StatusCode :: INTERNAL_SERVER_ERROR )
411413 . header ( "access-control-allow-origin" , "*" )
412414 . header (
413415 "access-control-allow-headers" ,
414416 "Content-Type, Authorization" ,
415417 )
416- . body ( format ! ( "{}" , e) . into ( ) )
418+ . body ( Full :: new ( Bytes :: from ( format ! ( "{}" , e) ) ) )
417419 {
418420 Ok ( r) => r,
419421 Err ( e) => json_response_pretty ( & format ! ( "{}" , e) ) ,
420422 }
421423}
422424
423- fn create_ok_response ( json : & str ) -> Response < Body > {
425+ fn create_ok_response ( json : & str ) -> Response < Full < Bytes > > {
424426 match Response :: builder ( )
425427 . status ( StatusCode :: OK )
426428 . header ( "access-control-allow-origin" , "*" )
@@ -429,7 +431,7 @@ fn create_ok_response(json: &str) -> Response<Body> {
429431 "Content-Type, Authorization" ,
430432 )
431433 . header ( hyper:: header:: CONTENT_TYPE , "application/json" )
432- . body ( json. to_string ( ) . into ( ) )
434+ . body ( Full :: new ( Bytes :: from ( json. to_string ( ) ) ) )
433435 {
434436 Ok ( r) => r,
435437 Err ( e) => json_response_pretty ( & format ! ( "{}" , e) ) ,
@@ -440,7 +442,7 @@ fn create_ok_response(json: &str) -> Response<Body> {
440442///
441443/// Whenever the status code is `StatusCode::OK` the text parameter should be
442444/// valid JSON as the content type header will be set to `application/json'
443- fn response < T : Into < Body > > ( status : StatusCode , text : T ) -> Response < Body > {
445+ fn response < T : Into < Bytes > > ( status : StatusCode , text : T ) -> Response < Full < Bytes > > {
444446 let mut builder = Response :: builder ( ) ;
445447
446448 builder = builder
@@ -455,7 +457,7 @@ fn response<T: Into<Body>>(status: StatusCode, text: T) -> Response<Body> {
455457 builder = builder. header ( hyper:: header:: CONTENT_TYPE , "application/json" ) ;
456458 }
457459
458- match builder. body ( text. into ( ) ) {
460+ match builder. body ( Full :: new ( text. into ( ) ) ) {
459461 Ok ( r) => r,
460462 Err ( e) => json_response_pretty ( & format ! ( "{}" , e) ) ,
461463 }
0 commit comments