2015-02-11 22:18 GMT+03:00 <[email protected]>:
> Author: markt
> Date: Wed Feb 11 19:18:46 2015
> New Revision: 1659043
>
> URL: http://svn.apache.org/r1659043
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57534
> CORS Filter should only look at media type component of content type
>
> Modified:
> tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java
> tomcat/trunk/test/org/apache/catalina/filters/TestCorsFilter.java
>
> Modified: tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java
> URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java?rev=1659043&r1=1659042&r2=1659043&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/filters/CorsFilter.java Wed Feb 11
> 19:18:46 2015
> @@ -639,11 +639,10 @@ public final class CorsFilter implements
> } else if ("GET".equals(method) ||
> "HEAD".equals(method)) {
> requestType = CORSRequestType.SIMPLE;
> } else if ("POST".equals(method)) {
> - String contentType = request.getContentType();
> - if (contentType != null) {
> - contentType = contentType.toLowerCase().trim();
> + String mediaType =
> getMediaType(request.getContentType());
> + if (mediaType != null) {
> if (SIMPLE_HTTP_REQUEST_CONTENT_TYPE_VALUES
> - .contains(contentType)) {
> + .contains(mediaType)) {
> requestType = CORSRequestType.SIMPLE;
> } else {
> requestType = CORSRequestType.ACTUAL;
> @@ -662,6 +661,23 @@ public final class CorsFilter implements
> }
>
>
> + /*
> + * Return the lower case, trimmed value of the media type from the
> content
> + * type.
> + */
> + private String getMediaType(String contentType) {
> + if (contentType == null) {
> + return null;
> + }
> + String result = contentType.toLowerCase();
We usually use Locale.ENGLISH in such code.
> + int firstSemiColonIndex = result.indexOf(';');
> + if (firstSemiColonIndex > -1) {
> + result = result.substring(0, firstSemiColonIndex);
> + }
> + result = result.trim();
> + return result;
> + }
> +
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]