Skip to content

Commit 9da294a

Browse files
committed
HDFS-15110. HttpFS: post requests are not supported for path "/". Contributed by hemanthboyina.
1 parent 20a90c0 commit 9da294a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,30 @@ public Response delete(@PathParam("path") String path,
525525
return response;
526526
}
527527

528+
/**
529+
* Special binding for '/' as it is not handled by the wildcard binding.
530+
* @param is the inputstream for the request payload.
531+
* @param uriInfo the of the request.
532+
* @param op the HttpFS operation of the request.
533+
* @param params the HttpFS parameters of the request.
534+
*
535+
* @return the request response.
536+
*
537+
* @throws IOException thrown if an IO error occurred. Thrown exceptions are
538+
* handled by {@link HttpFSExceptionProvider}.
539+
* @throws FileSystemAccessException thrown if a FileSystemAccess related
540+
* error occurred. Thrown exceptions are handled by
541+
* {@link HttpFSExceptionProvider}.
542+
*/
543+
@POST
544+
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
545+
public Response postRoot(InputStream is, @Context UriInfo uriInfo,
546+
@QueryParam(OperationParam.NAME) OperationParam op,
547+
@Context Parameters params, @Context HttpServletRequest request)
548+
throws IOException, FileSystemAccessException {
549+
return post(is, uriInfo, "/", op, params, request);
550+
}
551+
528552
/**
529553
* Binding to handle POST requests.
530554
*

hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,5 +1790,15 @@ public void testErasureCodingPolicy() throws Exception {
17901790
putCmdWithReturn(dir1, "SETECPOLICY", "ecpolicy=" + ecPolicyName);
17911791
// Should return HTTP_OK
17921792
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn3.getResponseCode());
1793+
1794+
// test post operation with path as "/"
1795+
final String dir2 = "/";
1796+
URL url1 = new URL(TestJettyHelper.getJettyURL(),
1797+
MessageFormat.format("/webhdfs/v1{0}?user.name={1}&op={2}&{3}", dir2,
1798+
user, "UNSETECPOLICY", ""));
1799+
HttpURLConnection conn4 = (HttpURLConnection) url1.openConnection();
1800+
conn4.setRequestMethod("POST");
1801+
conn4.connect();
1802+
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn4.getResponseCode());
17931803
}
17941804
}

0 commit comments

Comments
 (0)