@@ -135,6 +135,7 @@ CommonStrings::CommonStrings()
135
135
, GRPC_ACCEPT_ENCODING_VALUE(" identity,gzip" )
136
136
, GRPC_STATUS(" grpc-status" )
137
137
, GRPC_MESSAGE(" grpc-message" )
138
+ , GRPC_TIMEOUT(" grpc-timeout" )
138
139
{}
139
140
140
141
static CommonStrings* common = NULL ;
@@ -1190,6 +1191,31 @@ void EndRunningCallMethodInPool(
1190
1191
::google::protobuf::Message* response,
1191
1192
::google::protobuf::Closure* done);
1192
1193
1194
+ static int64_t ConvertGrpcTimeoutToNS (int64_t timeout_value, const char timeout_unit) {
1195
+ switch (timeout_unit) {
1196
+ case ' H' :
1197
+ timeout_value *= (3600 * 1000000000L );
1198
+ break ;
1199
+ case ' M' :
1200
+ timeout_value *= (60 * 1000000000L );
1201
+ break ;
1202
+ case ' S' :
1203
+ timeout_value *= 1000000000L ;
1204
+ break ;
1205
+ case ' m' :
1206
+ timeout_value *= 1000000L ;
1207
+ break ;
1208
+ case ' u' :
1209
+ timeout_value *= 1000L ;
1210
+ case ' n' :
1211
+ break ;
1212
+ default :
1213
+ return -1 ;
1214
+ }
1215
+ return timeout_value;
1216
+ }
1217
+
1218
+
1193
1219
void ProcessHttpRequest (InputMessageBase *msg) {
1194
1220
const int64_t start_parse_us = butil::cpuwide_time_us ();
1195
1221
DestroyingPtr<HttpContext> imsg_guard (static_cast <HttpContext*>(msg));
@@ -1418,6 +1444,15 @@ void ProcessHttpRequest(InputMessageBase *msg) {
1418
1444
return ;
1419
1445
}
1420
1446
}
1447
+ const std::string* grpc_timeout = req_header.GetHeader (common->GRPC_TIMEOUT );
1448
+ if (grpc_timeout) {
1449
+ const char timeout_unit = grpc_timeout->back ();
1450
+ int64_t timeout_value_ns =
1451
+ ConvertGrpcTimeoutToNS ((int64_t )strtol (grpc_timeout->data (), NULL , 10 ), timeout_unit);
1452
+ if (timeout_value_ns >= 0 ) {
1453
+ accessor.set_deadline_ns (timeout_value_ns);
1454
+ }
1455
+ }
1421
1456
}
1422
1457
} else {
1423
1458
encoding = req_header.GetHeader (common->CONTENT_ENCODING );
@@ -1455,7 +1490,7 @@ void ProcessHttpRequest(InputMessageBase *msg) {
1455
1490
// A http server, just keep content as it is.
1456
1491
cntl->request_attachment ().swap (req_body);
1457
1492
}
1458
-
1493
+
1459
1494
google::protobuf::Closure* done = new HttpResponseSenderAsDone (&resp_sender);
1460
1495
imsg_guard.reset (); // optional, just release resourse ASAP
1461
1496
0 commit comments