tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: svn commit: r1405415 - in /tomcat/trunk: ./ java/org/apache/catalina/authenticator/ java/org/apache/catalina/connector/ java/org/apache/coyote/ java/org/apache/tomcat/util/http/parser/ test/org/apache/tomcat/util/http/parser/
Date Tue, 13 Nov 2012 08:48:26 GMT
2012/11/4  <markt@apache.org>:
> Author: markt
> Date: Sat Nov  3 20:46:02 2012
> New Revision: 1405415
>
> URL: http://svn.apache.org/viewvc?rev=1405415&view=rev
> Log:
> Move media-type parsing to the new parser and drop the JJTree based parser.
>
> Added:
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
>       - copied, changed from r1405399, tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser2.java
> Removed:
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstAttribute.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstMediaType.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstParameter.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstSubType.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstType.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/AstValue.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.jjt
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser2.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParserConstants.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParserTokenManager.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParserTreeConstants.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/JJTHttpParserState.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/Node.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/ParseException.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/SimpleCharStream.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/SimpleNode.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/Token.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/TokenMgrError.java
> Modified:
>     tomcat/trunk/build.xml
>     tomcat/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java
>     tomcat/trunk/java/org/apache/catalina/connector/Response.java
>     tomcat/trunk/java/org/apache/coyote/Response.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java
>     tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java
>     tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
>     tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java

> Copied: tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java (from r1405399,
tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser2.java)

> @@ -198,60 +190,59 @@ public class HttpParser2 {
>              return null;
>          }
>
> -        skipLws(input);
> -
> -        Map<String,String> parameters = new HashMap<>();
> +        LinkedHashMap<String,String> parameters = new LinkedHashMap<>();
>
>          SkipConstantResult lookForSemiColon = skipConstant(input, ";");
>          if (lookForSemiColon == SkipConstantResult.NOT_FOUND) {
>              return null;
>          }
>          while (lookForSemiColon == SkipConstantResult.FOUND) {
> -            skipLws(input);
>              String attribute = readToken(input);
> -            skipLws(input);
>
> -            if (skipConstant(input, "=") != SkipConstantResult.FOUND) {
> -                return null;
> +            if (skipConstant(input, "=") == SkipConstantResult.FOUND) {
> +                String value = readTokenOrQuotedString(input, true);
> +                parameters.put(attribute, value);
> +            } else {
> +                parameters.put(attribute, "");
>              }
>
> -            skipLws(input);
> -            String value = readTokenOrQuotedString(input, true);
> -            skipLws(input);
> -
> -            parameters.put(attribute.toLowerCase(), value);

The above old code does attribute.toLowerCase(). The new code does not.

Looking into MediaType#MediaType(type,subtype,parameters) constructor, it calls
String cs = parameters.get("charset");

So it works with lowercase.
According to RFC2616 ch. 3.7 Media Types,
"The type, subtype, and parameter attribute names are case-insensitive."


> -
>              lookForSemiColon = skipConstant(input, ";");
>              if (lookForSemiColon == SkipConstantResult.NOT_FOUND) {
>                  return null;
>              }
>          }
>
> -        String charset = parameters.remove("charset");
> -        StringBuilder noCharSet = new StringBuilder();
> -        noCharSet.append(type);
> -        noCharSet.append('/');
> -        noCharSet.append(subtype);
> -        for (Map.Entry<String, String> entry : parameters.entrySet()) {
> -            noCharSet.append(';');
> -            // Workaround for Adobe Read 9 plug-in on IE bug
> -            // Can be removed after 26 June 2013 (EOL of Reader 9)
> -            // See BZ 53814
> -            noCharSet.append(' ');
> -            noCharSet.append(entry.getKey());
> -            noCharSet.append('=');
> -            noCharSet.append(entry.getValue());
> +        return new MediaType(type, subtype, parameters);
> +    }
> +

(...)

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message