-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Optionally include Content-Disposition header in statement results API response #17827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,7 @@ public class SqlStatementResource | |
| { | ||
|
|
||
| public static final String RESULT_FORMAT = "__resultFormat"; | ||
| public static final String CONTENT_DISPOSITION_RESPONSE_HEADER = "Content-Disposition"; | ||
| private static final Logger log = new Logger(SqlStatementResource.class); | ||
| private final SqlStatementFactory msqSqlStatementFactory; | ||
| private final ObjectMapper jsonMapper; | ||
|
|
@@ -277,6 +278,7 @@ public Response doGetResults( | |
| @PathParam("id") final String queryId, | ||
| @QueryParam("page") Long page, | ||
| @QueryParam("resultFormat") String resultFormat, | ||
| @QueryParam("filename") String filename, | ||
| @Context final HttpServletRequest req | ||
| ) | ||
| { | ||
|
|
@@ -309,10 +311,18 @@ public Response doGetResults( | |
| ); | ||
| throwIfQueryIsNotSuccessful(queryId, statusPlus); | ||
|
|
||
| final String contentDispositionHeaderValue = filename != null ? StringUtils.format("attachment; filename=%s", filename) : null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there should be some validation of
as to "allowed characters", please check into what happens if |
||
|
|
||
| Optional<List<ColumnNameAndTypes>> signature = SqlStatementResourceHelper.getSignature(msqControllerTask); | ||
| if (!signature.isPresent() || MSQControllerTask.isIngestion(msqControllerTask.getQuerySpec())) { | ||
| // Since it's not a select query, nothing to return. | ||
| return Response.ok().build(); | ||
| final Response.ResponseBuilder responseBuilder = Response.ok(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please factor this into a method so it doesn't need to be repeated three times. the signature of the method could be |
||
|
|
||
| if (contentDispositionHeaderValue != null) { | ||
| responseBuilder.header(CONTENT_DISPOSITION_RESPONSE_HEADER, contentDispositionHeaderValue); | ||
| } | ||
|
|
||
| return responseBuilder.build(); | ||
| } | ||
|
|
||
| // returning results | ||
|
|
@@ -321,18 +331,30 @@ public Response doGetResults( | |
| results = getResultYielder(queryId, page, msqControllerTask, closer); | ||
| if (!results.isPresent()) { | ||
| // no results, return empty | ||
| return Response.ok().build(); | ||
| final Response.ResponseBuilder responseBuilder = Response.ok(); | ||
|
|
||
| if (contentDispositionHeaderValue != null) { | ||
| responseBuilder.header(CONTENT_DISPOSITION_RESPONSE_HEADER, contentDispositionHeaderValue); | ||
| } | ||
|
|
||
| return responseBuilder.build(); | ||
| } | ||
|
|
||
| ResultFormat preferredFormat = getPreferredResultFormat(resultFormat, msqControllerTask.getQuerySpec()); | ||
| return Response.ok((StreamingOutput) outputStream -> resultPusher( | ||
| final Response.ResponseBuilder responseBuilder = Response.ok((StreamingOutput) outputStream -> resultPusher( | ||
| queryId, | ||
| signature, | ||
| closer, | ||
| results, | ||
| new CountingOutputStream(outputStream), | ||
| preferredFormat | ||
| )).build(); | ||
| )); | ||
|
|
||
| if (contentDispositionHeaderValue != null) { | ||
| responseBuilder.header(CONTENT_DISPOSITION_RESPONSE_HEADER, contentDispositionHeaderValue); | ||
| } | ||
|
|
||
| return responseBuilder.build(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once a max length and allowed characters are implemented, document them here.