Skip to content
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

Encode the path in uri #23907

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import static com.facebook.presto.server.security.RoleType.ADMIN;
Expand Down Expand Up @@ -67,9 +70,16 @@ public void getTaskInfo(@PathParam("taskId") TaskId taskId,
proxyTaskInfoResponse(servletRequest, asyncResponse, uriInfo, taskId);
}

private URI createTaskInfoUri(BasicQueryInfo queryInfo, UriInfo uriInfo)
private URI createTaskInfoUri(BasicQueryInfo queryInfo, TaskId taskId)
{
return UriBuilder.fromUri(queryInfo.getSelf()).replacePath(uriInfo.getPath()).build();
try {
return UriBuilder.fromUri(queryInfo.getSelf())
.replacePath("/v1/taskInfo/" + URLEncoder.encode(taskId.toString(), StandardCharsets.UTF_8.toString()))
.build();
}
catch (UnsupportedEncodingException e) {
throw new AssertionError("UTF-8 encoding should always be supported", e);
}
}

private void proxyTaskInfoResponse(HttpServletRequest servletRequest, AsyncResponse asyncResponse, UriInfo uriInfo, TaskId taskId)
Expand All @@ -80,7 +90,7 @@ private void proxyTaskInfoResponse(HttpServletRequest servletRequest, AsyncRespo
.findFirst();

if (queryInfo.isPresent()) {
proxyHelper.performRequest(servletRequest, asyncResponse, createTaskInfoUri(queryInfo.get(), uriInfo));
proxyHelper.performRequest(servletRequest, asyncResponse, createTaskInfoUri(queryInfo.get(), taskId));
}
else {
asyncResponse.resume(Response.status(NOT_FOUND).type(MediaType.APPLICATION_JSON).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private static URI getQueryHtmlUri(QueryId queryId, UriInfo uriInfo, String xFor
URI uri = uriInfo.getRequestUriBuilder()
.scheme(getScheme(xForwardedProto, uriInfo))
.replacePath("ui/query.html")
.replaceQuery(queryId.toString())
.replaceQuery(urlEncode(queryId.toString()))
.build();
return prependUri(uri, xPrestoPrefixUrl);
}
Expand All @@ -397,10 +397,10 @@ public static URI getQueuedUri(QueryId queryId, String slug, long token, UriInfo
UriBuilder uriBuilder = uriInfo.getBaseUriBuilder()
.scheme(getScheme(xForwardedProto, uriInfo))
.replacePath("/v1/statement/queued")
.path(queryId.toString())
.path(String.valueOf(token))
.path(urlEncode(queryId.toString()))
.path(urlEncode(String.valueOf(token)))
.replaceQuery("")
.queryParam("slug", slug);
.queryParam("slug", urlEncode(slug));
if (binaryResults) {
uriBuilder.queryParam("binaryResults", "true");
}
Expand Down
Loading