-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
HDFS-17040. Namenode web UI should set content type to application/octet-stream when uploading a file. #5721
Conversation
…stream when uploading a file
🎊 +1 overall
This message was automatically generated. |
@@ -518,7 +518,8 @@ | |||
url: url, | |||
data: file.file, | |||
processData: false, | |||
crossDomain: true | |||
crossDomain: true, | |||
contentType: 'application/octet-stream' |
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.
Question: Is this a js running in client browsers? The change here is to change the contentType
when uploading a file from a client browser to HDFS. Is it correct?
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.
@szetszwo Yes, this is the JS code running in the client browser. By default the contentType is set to application/x-www-form-urlencoded
now it's explicitly set to application/octet-stream
.
However I a found a problem when testing with newer browsers with CORS enabled. It works when I try it via Knox or with a browser where CORS is disabled.
But in new browsers with Cross-Origin Resource Sharing policy prevents changing the contentType since it's not included in the Access-Control-Allow-Headers
header. Only the accept header is included in Access-Control-Allow-Headers
.
Access-Control-Allow-Headers: Accept
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Origin: *
The CrossOriginFilter contains the content type so I don't know why I only see Accept
Line 74 in 9de13f8
"X-Requested-With,Content-Type,Accept,Origin"; |
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.
The list is the default values. It can be overridden by init parameter; see
Lines 176 to 185 in 9de13f8
private void initializeAllowedHeaders(FilterConfig filterConfig) { | |
String allowedHeadersConfig = | |
filterConfig.getInitParameter(ALLOWED_HEADERS); | |
if (allowedHeadersConfig == null) { | |
allowedHeadersConfig = ALLOWED_HEADERS_DEFAULT; | |
} | |
allowedHeaders.addAll( | |
Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*"))); | |
LOG.info("Allowed Headers: " + getAllowedHeadersHeader()); | |
} |
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.
Yes I've seen that, but it wasn't overridden. Even if I explicitly added
<property>
<name>hadoop.http.cross-origin.allowed-headers</name>
<value>X-Requested-With,Content-Type,Accept,Origin</value>
</property>
to core-site.xml, it was not picked up for some reason.
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.
@szetszwo I'm not sure the CORS problem still exists. I've tested this using Chrome browser and with maximum security enabled the change was still working.
@@ -518,7 +518,8 @@ | |||
url: url, | |||
data: file.file, | |||
processData: false, | |||
crossDomain: true | |||
crossDomain: true, | |||
contentType: 'application/octet-stream' |
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.
@szetszwo I'm not sure the CORS problem still exists. I've tested this using Chrome browser and with maximum security enabled the change was still working.
Thanks for the patch, looking good to me +1 I've tested this change in a cluster by trying to upload a file containing the text "hello %" via namenode ui. The change is indeed working. I haven't found a CORS related problem or at least Chrome browsers security levels don't seem to affect it. |
@szetszwo could you please take another look at this PR? |
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.
+1 the change looks good.
@Galsza , thanks a lot for testing this!
Since this pull request already passed all the checks earlier, let's just merge it. |
Description of PR
HDFS-17040
When uploading a file WebHDFS will set the content type to application/x-www-form-urlencoded, as this is the default used by jQuery
This causes knox to urlencode the request body so that uploading a CVS file 1,2,3 will result 1%2C2%2C3.
Instead of application/x-www-form-urlencoded I think the encoding should be set to application/octet-stream.
How was this patch tested?
Pending
For code changes:
content type is explicitly set to octet stream