Skip to content

Commit

Permalink
Handle HEAD request. (#34)
Browse files Browse the repository at this point in the history
* Handle HEAD request.

* Try with GET if HEAD fails.

* Address comments.

* Format file.
  • Loading branch information
chowchow316 authored Jan 13, 2017
1 parent add363a commit ee3cdee
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion contrib/endpoints/src/api_manager/context/service_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const double kDefaultTraceSampleQps = 0.1;
// The time window to send intermediate report for Grpc streaming (second).
// Default to 10s.
const int kIntermediateReportInterval = 10;

const char kHTTPHeadMethod[] = "HEAD";
const char kHTTPGetMethod[] = "GET";
}

ServiceContext::ServiceContext(std::unique_ptr<ApiManagerEnvInterface> env,
Expand Down Expand Up @@ -74,7 +77,15 @@ MethodCallInfo ServiceContext::GetMethodCallInfo(
if (config_ == nullptr) {
return MethodCallInfo();
}
return config_->GetMethodCallInfo(http_method, url, query_params);
MethodCallInfo method_call_info =
config_->GetMethodCallInfo(http_method, url, query_params);
// HEAD should be treated as GET unless it is specified from service_config.
if (method_call_info.method_info == nullptr &&
http_method == kHTTPHeadMethod) {
method_call_info =
config_->GetMethodCallInfo(kHTTPGetMethod, url, query_params);
}
return method_call_info;
}

const std::string& ServiceContext::project_id() const {
Expand Down

0 comments on commit ee3cdee

Please sign in to comment.