Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions server/src/main/java/io/druid/server/QueryResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class QueryResource
@Deprecated // use SmileMediaTypes.APPLICATION_JACKSON_SMILE
private static final String APPLICATION_SMILE = "application/smile";

private static final int RESPONSE_CTX_HEADER_LEN_LIMIT = 7*1024;

private final ServerConfig config;
private final ObjectMapper jsonMapper;
private final ObjectMapper smileMapper;
Expand Down Expand Up @@ -177,7 +179,7 @@ public Object accumulate(Object accumulated, Object in)

try {
final Query theQuery = query;
return Response
Response.ResponseBuilder builder = Response
.ok(
new StreamingOutput()
{
Expand Down Expand Up @@ -220,8 +222,19 @@ public void write(OutputStream outputStream) throws IOException, WebApplicationE
},
contentType
)
.header("X-Druid-Query-Id", queryId)
.header("X-Druid-Response-Context", jsonMapper.writeValueAsString(responseContext))
.header("X-Druid-Query-Id", queryId);

//Limit the response-context header, see https://github.com/druid-io/druid/issues/2331
//Note that Response.ResponseBuilder.header(String key,Object value).build() calls value.toString()
//and encodes the string using ASCII, so 1 char is = 1 byte
String responseCtxString = jsonMapper.writeValueAsString(responseContext);
if (responseCtxString.length() > RESPONSE_CTX_HEADER_LEN_LIMIT) {
log.warn("Response Context truncated for id [%s] . Full context is [%s].", queryId, responseCtxString);
responseCtxString = responseCtxString.substring(0, RESPONSE_CTX_HEADER_LEN_LIMIT);
}

return builder
.header("X-Druid-Response-Context", responseCtxString)
.build();
}
catch (Exception e) {
Expand Down