@@ -392,9 +392,13 @@ proxygen::RequestHandler* TaskResource::deleteTask(
392
392
message->getQueryParam (protocol::PRESTO_ABORT_TASK_URL_PARAM) == " true" ;
393
393
}
394
394
bool summarize = message->hasQueryParam (" summarize" );
395
+ auto & headers = message->getHeaders ();
396
+ const auto & acceptHeader = headers.getSingleOrEmpty (proxygen::HTTP_HEADER_ACCEPT);
397
+ const auto sendThrift =
398
+ acceptHeader.find (http::kMimeTypeApplicationThrift ) != std::string::npos;
395
399
396
400
return new http::CallbackRequestHandler (
397
- [this , taskId, abort, summarize](
401
+ [this , taskId, abort, summarize, sendThrift ](
398
402
proxygen::HTTPMessage* /* message*/ ,
399
403
const std::vector<std::unique_ptr<folly::IOBuf>>& /* body*/ ,
400
404
proxygen::ResponseHandler* downstream,
@@ -407,12 +411,19 @@ proxygen::RequestHandler* TaskResource::deleteTask(
407
411
return std::move (taskInfo);
408
412
})
409
413
.via (folly::EventBaseManager::get ()->getEventBase ())
410
- .thenValue ([taskId, downstream, handlerState](auto && taskInfo) {
414
+ .thenValue ([taskId, downstream, handlerState, sendThrift ](auto && taskInfo) {
411
415
if (!handlerState->requestExpired ()) {
412
416
if (taskInfo == nullptr ) {
413
417
sendTaskNotFound (downstream, taskId);
414
418
}
415
- http::sendOkResponse (downstream, json (*taskInfo));
419
+ if (sendThrift) {
420
+ thrift::TaskInfo thriftTaskInfo;
421
+ toThrift (*taskInfo, thriftTaskInfo);
422
+ http::sendOkThriftResponse (
423
+ downstream, thriftWrite (thriftTaskInfo));
424
+ } else {
425
+ http::sendOkResponse (downstream, json (*taskInfo));
426
+ }
416
427
}
417
428
})
418
429
.thenError (
@@ -604,8 +615,13 @@ proxygen::RequestHandler* TaskResource::getTaskInfo(
604
615
auto maxWait = getMaxWait (message);
605
616
bool summarize = message->hasQueryParam (" summarize" );
606
617
618
+ auto & headers = message->getHeaders ();
619
+ const auto & acceptHeader = headers.getSingleOrEmpty (proxygen::HTTP_HEADER_ACCEPT);
620
+ const auto sendThrift =
621
+ acceptHeader.find (http::kMimeTypeApplicationThrift ) != std::string::npos;
622
+
607
623
return new http::CallbackRequestHandler (
608
- [this , taskId, currentState, maxWait, summarize](
624
+ [this , taskId, currentState, maxWait, summarize, sendThrift ](
609
625
proxygen::HTTPMessage* /* message*/ ,
610
626
const std::vector<std::unique_ptr<folly::IOBuf>>& /* body*/ ,
611
627
proxygen::ResponseHandler* downstream,
@@ -619,16 +635,23 @@ proxygen::RequestHandler* TaskResource::getTaskInfo(
619
635
maxWait,
620
636
summarize,
621
637
handlerState,
622
- downstream]() {
638
+ downstream,
639
+ sendThrift]() {
623
640
taskManager_
624
641
.getTaskInfo (
625
642
taskId, summarize, currentState, maxWait, handlerState)
626
643
.via (evb)
627
- .thenValue ([downstream, taskId, handlerState](
644
+ .thenValue ([downstream, taskId, handlerState, sendThrift ](
628
645
std::unique_ptr<protocol::TaskInfo> taskInfo) {
629
646
if (!handlerState->requestExpired ()) {
630
- json taskInfoJson = *taskInfo;
631
- http::sendOkResponse (downstream, taskInfoJson);
647
+ if (sendThrift) {
648
+ thrift::TaskInfo thriftTaskInfo;
649
+ toThrift (*taskInfo, thriftTaskInfo);
650
+ http::sendOkThriftResponse (
651
+ downstream, thriftWrite (thriftTaskInfo));
652
+ } else {
653
+ http::sendOkResponse (downstream, json (*taskInfo));
654
+ }
632
655
}
633
656
})
634
657
.thenError (
0 commit comments