@@ -248,9 +248,8 @@ static bool rest_headers(const std::any& context,
248248 ssHeader << pindex->GetBlockHeader ();
249249 }
250250
251- std::string binaryHeader = ssHeader.str ();
252251 req->WriteHeader (" Content-Type" , " application/octet-stream" );
253- req->WriteReply (HTTP_OK, binaryHeader );
252+ req->WriteReply (HTTP_OK, ssHeader );
254253 return true ;
255254 }
256255
@@ -321,9 +320,8 @@ static bool rest_block(const std::any& context,
321320
322321 switch (rf) {
323322 case RESTResponseFormat::BINARY: {
324- const std::string binaryBlock{block_data.begin (), block_data.end ()};
325323 req->WriteHeader (" Content-Type" , " application/octet-stream" );
326- req->WriteReply (HTTP_OK, binaryBlock );
324+ req->WriteReply (HTTP_OK, std::as_bytes (std::span{block_data}) );
327325 return true ;
328326 }
329327
@@ -451,9 +449,8 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
451449 ssHeader << header;
452450 }
453451
454- std::string binaryHeader = ssHeader.str ();
455452 req->WriteHeader (" Content-Type" , " application/octet-stream" );
456- req->WriteReply (HTTP_OK, binaryHeader );
453+ req->WriteReply (HTTP_OK, ssHeader );
457454 return true ;
458455 }
459456 case RESTResponseFormat::HEX: {
@@ -548,9 +545,8 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
548545 DataStream ssResp{};
549546 ssResp << filter;
550547
551- std::string binaryResp = ssResp.str ();
552548 req->WriteHeader (" Content-Type" , " application/octet-stream" );
553- req->WriteReply (HTTP_OK, binaryResp );
549+ req->WriteReply (HTTP_OK, ssResp );
554550 return true ;
555551 }
556552 case RESTResponseFormat::HEX: {
@@ -729,9 +725,8 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
729725 DataStream ssTx;
730726 ssTx << TX_WITH_WITNESS (tx);
731727
732- std::string binaryTx = ssTx.str ();
733728 req->WriteHeader (" Content-Type" , " application/octet-stream" );
734- req->WriteReply (HTTP_OK, binaryTx );
729+ req->WriteReply (HTTP_OK, ssTx );
735730 return true ;
736731 }
737732
@@ -900,10 +895,9 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
900895 // use exact same output as mentioned in Bip64
901896 DataStream ssGetUTXOResponse{};
902897 ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
903- std::string ssGetUTXOResponseString = ssGetUTXOResponse.str ();
904898
905899 req->WriteHeader (" Content-Type" , " application/octet-stream" );
906- req->WriteReply (HTTP_OK, ssGetUTXOResponseString );
900+ req->WriteReply (HTTP_OK, ssGetUTXOResponse );
907901 return true ;
908902 }
909903
@@ -981,7 +975,7 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
981975 DataStream ss_blockhash{};
982976 ss_blockhash << pblockindex->GetBlockHash ();
983977 req->WriteHeader (" Content-Type" , " application/octet-stream" );
984- req->WriteReply (HTTP_OK, ss_blockhash. str () );
978+ req->WriteReply (HTTP_OK, ss_blockhash);
985979 return true ;
986980 }
987981 case RESTResponseFormat::HEX: {
0 commit comments