Skip to content

Commit 5348dd4

Browse files
authored
support for multipart/form-data (#14771)
1 parent d492c81 commit 5348dd4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ydb/core/viewer/viewer_query.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TJsonQuery : public TViewerPipeClient {
4747
NHttp::THttpOutgoingResponsePtr HttpResponse;
4848
std::vector<bool> ResultSetHasColumns;
4949
bool ConcurrentResults = false;
50+
TString ContentType;
5051

5152
public:
5253
ESchemaType StringToSchemaType(const TString& schemaStr) {
@@ -129,8 +130,16 @@ class TJsonQuery : public TViewerPipeClient {
129130
if (Streaming) {
130131
NHttp::THeaders headers(HttpEvent->Get()->Request->Headers);
131132
TStringBuf accept = headers["Accept"];
132-
if (accept.find("multipart/x-mixed-replace") == TString::npos) {
133-
return TBase::ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "Multipart request must accept multipart/x-mixed-replace content"), "BadRequest");
133+
auto posMixedReplace = accept.find("multipart/x-mixed-replace");
134+
auto posFormData = accept.find("multipart/form-data");
135+
auto posFirst = std::min(posMixedReplace, posFormData);
136+
if (posFirst == TString::npos) {
137+
return TBase::ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "Multipart request must accept multipart content-type"), "BadRequest");
138+
}
139+
if (posFirst == posMixedReplace) {
140+
ContentType = "multipart/x-mixed-replace";
141+
} else if (posFirst == posFormData) {
142+
ContentType = "multipart/form-data";
134143
}
135144
}
136145
if (Streaming && QueryId.empty()) {
@@ -238,7 +247,7 @@ class TJsonQuery : public TViewerPipeClient {
238247
}
239248
CreateSessionResponse = MakeRequest<NKqp::TEvKqp::TEvCreateSessionResponse>(NKqp::MakeKqpProxyID(SelfId().NodeId()), event.release());
240249
if (Streaming) {
241-
HttpResponse = HttpEvent->Get()->Request->CreateResponseString(Viewer->GetChunkedHTTPOK(GetRequest(), "multipart/x-mixed-replace;boundary=boundary"));
250+
HttpResponse = HttpEvent->Get()->Request->CreateResponseString(Viewer->GetChunkedHTTPOK(GetRequest(), ContentType + ";boundary=boundary"));
242251
Send(HttpEvent->Sender, new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(HttpResponse));
243252
}
244253
}
@@ -1022,6 +1031,10 @@ class TJsonQuery : public TViewerPipeClient {
10221031
schema:
10231032
type: object
10241033
description: format depends on schema parameter
1034+
multipart/form-data:
1035+
schema:
1036+
type: object
1037+
description: format depends on schema parameter
10251038
400:
10261039
description: Bad Request
10271040
403:

0 commit comments

Comments
 (0)