Skip to content

Commit 4bc8339

Browse files
authored
Merge pull request #1782 from bitshares/1772_http_server
Fix broken http parser
2 parents 14e0f17 + 6c630f6 commit 4bc8339

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

programs/cli_wallet/main.cpp

+20-21
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#include <fc/io/json.hpp>
3131
#include <fc/io/stdio.hpp>
32-
#include <fc/network/http/server.hpp>
3332
#include <fc/network/http/websocket.hpp>
3433
#include <fc/rpc/cli.hpp>
3534
#include <fc/rpc/http_api.hpp>
@@ -77,10 +76,12 @@ int main( int argc, char** argv )
7776
("server-rpc-endpoint,s", bpo::value<string>()->implicit_value("ws://127.0.0.1:8090"), "Server websocket RPC endpoint")
7877
("server-rpc-user,u", bpo::value<string>(), "Server Username")
7978
("server-rpc-password,p", bpo::value<string>(), "Server Password")
80-
("rpc-endpoint,r", bpo::value<string>()->implicit_value("127.0.0.1:8091"), "Endpoint for wallet websocket RPC to listen on")
79+
("rpc-endpoint,r", bpo::value<string>()->implicit_value("127.0.0.1:8091"),
80+
"Endpoint for wallet websocket RPC to listen on (DEPRECATED, use rpc-http-endpoint instead)")
8181
("rpc-tls-endpoint,t", bpo::value<string>()->implicit_value("127.0.0.1:8092"), "Endpoint for wallet websocket TLS RPC to listen on")
8282
("rpc-tls-certificate,c", bpo::value<string>()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC")
83-
("rpc-http-endpoint,H", bpo::value<string>()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on")
83+
("rpc-http-endpoint,H", bpo::value<string>()->implicit_value("127.0.0.1:8093"),
84+
"Endpoint for wallet HTTP and websocket RPC to listen on")
8485
("daemon,d", "Run the wallet in daemon mode" )
8586
("wallet-file,w", bpo::value<string>()->implicit_value("wallet.json"), "wallet to load")
8687
("chain-id", bpo::value<string>(), "chain ID to connect to")
@@ -205,15 +206,16 @@ int main( int argc, char** argv )
205206

206207
fc::api<wallet_api> wapi(wapiptr);
207208

208-
auto _websocket_server = std::make_shared<fc::http::websocket_server>();
209+
std::shared_ptr<fc::http::websocket_server> _websocket_server;
209210
if( options.count("rpc-endpoint") )
210211
{
212+
_websocket_server = std::make_shared<fc::http::websocket_server>();
211213
_websocket_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){
212214
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
213215
wsc->register_api(wapi);
214216
c->set_session_data( wsc );
215217
});
216-
ilog( "Listening for incoming RPC requests on ${p}", ("p", options.at("rpc-endpoint").as<string>() ));
218+
ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", ("p", options.at("rpc-endpoint").as<string>() ));
217219
_websocket_server->listen( fc::ip::endpoint::from_string(options.at("rpc-endpoint").as<string>()) );
218220
_websocket_server->start_accept();
219221
}
@@ -222,37 +224,34 @@ int main( int argc, char** argv )
222224
if( options.count( "rpc-tls-certificate" ) )
223225
cert_pem = options.at("rpc-tls-certificate").as<string>();
224226

225-
auto _websocket_tls_server = std::make_shared<fc::http::websocket_tls_server>(cert_pem);
227+
std::shared_ptr<fc::http::websocket_tls_server> _websocket_tls_server;
226228
if( options.count("rpc-tls-endpoint") )
227229
{
230+
_websocket_tls_server = std::make_shared<fc::http::websocket_tls_server>(cert_pem);
228231
_websocket_tls_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){
229232
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
230233
wsc->register_api(wapi);
231234
c->set_session_data( wsc );
232235
});
233-
ilog( "Listening for incoming TLS RPC requests on ${p}",
236+
ilog( "Listening for incoming HTTPS and WSS RPC requests on ${p}",
234237
("p", options.at("rpc-tls-endpoint").as<string>()) );
235238
_websocket_tls_server->listen( fc::ip::endpoint::from_string(options.at("rpc-tls-endpoint").as<string>()) );
236239
_websocket_tls_server->start_accept();
237240
}
238241

239-
auto _http_server = std::make_shared<fc::http::server>();
242+
std::shared_ptr<fc::http::websocket_server> _http_ws_server;
240243
if( options.count("rpc-http-endpoint" ) )
241244
{
242-
ilog( "Listening for incoming HTTP RPC requests on ${p}",
245+
_http_ws_server = std::make_shared<fc::http::websocket_server>();
246+
ilog( "Listening for incoming HTTP and WS RPC requests on ${p}",
243247
("p", options.at("rpc-http-endpoint").as<string>()) );
244-
_http_server->listen( fc::ip::endpoint::from_string( options.at( "rpc-http-endpoint" ).as<string>() ) );
245-
//
246-
// due to implementation, on_request() must come AFTER listen()
247-
//
248-
_http_server->on_request(
249-
[&wapi]( const fc::http::request& req, const fc::http::server::response& resp )
250-
{
251-
std::shared_ptr< fc::rpc::http_api_connection > conn =
252-
std::make_shared< fc::rpc::http_api_connection >( GRAPHENE_MAX_NESTED_OBJECTS );
253-
conn->register_api( wapi );
254-
conn->on_request( req, resp );
255-
} );
248+
_http_ws_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){
249+
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_MAX_NESTED_OBJECTS);
250+
wsc->register_api(wapi);
251+
c->set_session_data( wsc );
252+
});
253+
_http_ws_server->listen( fc::ip::endpoint::from_string(options.at("rpc-http-endpoint").as<string>()) );
254+
_http_ws_server->start_accept();
256255
}
257256

258257
if( !options.count( "daemon" ) )

0 commit comments

Comments
 (0)