Skip to content

Commit

Permalink
Fixed web service crash (#4334)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
dutor and Sophie-Xie committed Jun 20, 2022
1 parent dc1cb64 commit 533d359
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/webservice/GetFlagsHandler.cpp
Expand Up @@ -22,7 +22,7 @@ using proxygen::ResponseBuilder;
using proxygen::UpgradeProtocol;

void GetFlagsHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::GET) {
if (!headers->getMethod() || headers->getMethod().value() != HTTPMethod::GET) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/webservice/GetStatsHandler.cpp
Expand Up @@ -24,7 +24,7 @@ using proxygen::ResponseBuilder;
using proxygen::UpgradeProtocol;

void GetStatsHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::GET) {
if (!headers->getMethod() || headers->getMethod().value() != HTTPMethod::GET) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
Expand Down
3 changes: 3 additions & 0 deletions src/webservice/Router.cpp
Expand Up @@ -104,6 +104,9 @@ proxygen::RequestHandler *Route::generateHandler(const std::string &path) const

proxygen::RequestHandler *Router::dispatch(const proxygen::HTTPMessage *msg) const {
for (Route *r = head_; r != nullptr; r = r->next()) {
if (!msg->getMethod()) {
break;
}
if (r->matches(msg->getMethod().value(), msg->getPath())) {
return r->generateHandler(msg->getPath());
}
Expand Down
2 changes: 1 addition & 1 deletion src/webservice/SetFlagsHandler.cpp
Expand Up @@ -21,7 +21,7 @@ using proxygen::ResponseBuilder;
using proxygen::UpgradeProtocol;

void SetFlagsHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::PUT) {
if (!headers->getMethod() || headers->getMethod().value() != HTTPMethod::PUT) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/webservice/StatusHandler.cpp
Expand Up @@ -20,7 +20,7 @@ using proxygen::ResponseBuilder;
using proxygen::UpgradeProtocol;

void StatusHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::GET) {
if (!headers->getMethod() || headers->getMethod().value() != HTTPMethod::GET) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
Expand Down

0 comments on commit 533d359

Please sign in to comment.