[ https://issues.apache.org/jira/browse/DIRMINA-666?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677957#action_12677957 ]
Janne Siren commented on DIRMINA-666: ------------------------------------- Here is the fix proposal. This is made on top of MINA-1.1.0 (Thanks Alex). We have tested that the problem exists also in latest stable version 1.1.7, but we are quite busy with other tasks so we did not made corrections to 1.1.7 version. We have not tested with unstable 2.0.x version. Hopefully you can merge this to stable 1.1.x branch and check that this problem does not exist or gets corrected in unstable 2.0.x branch. Index: HttpRequestDecoder.java =================================================================== --- HttpRequestDecoder.java (revision 1) +++ HttpRequestDecoder.java (working copy) @@ -43,7 +43,8 @@ */ public class HttpRequestDecoder extends MessageDecoderAdapter { - private static final byte[] CONTENT_LENGTH = new String( "Content-Length:" ) + // modified to support case-insensitive header + private static final byte[] CONTENT_LENGTH = new String( "content-length:" ) .getBytes(); private CharsetDecoder decoder = Charset.defaultCharset() @@ -130,7 +131,8 @@ boolean found = false; for( int j = 0; j < CONTENT_LENGTH.length; j++ ) { - if( in.get( i + j ) != CONTENT_LENGTH[ j ] ) + // modified to support case-insensitive header + if (in.get(i + j) != CONTENT_LENGTH[j] && in.get(i + j) != (CONTENT_LENGTH[j]-20)) { found = false; break; @@ -198,6 +200,10 @@ while( ( line = rdr.readLine() ) != null && line.length() > 0 ) { String[] tokens = line.split( ": " ); + // modified to support case insensitive header + if (tokens[0].equalsIgnoreCase("content-length")) { + tokens[0] = "Content-Length"; + } map.put( tokens[ 0 ], new String[] { tokens[ 1 ] } ); } > HTTP header parsing example incompatible with rfc2616 / content-length field > name should be interrepted as case-insensitive > --------------------------------------------------------------------------------------------------------------------------- > > Key: DIRMINA-666 > URL: https://issues.apache.org/jira/browse/DIRMINA-666 > Project: MINA > Issue Type: Bug > Components: Example > Affects Versions: 1.1.0 > Environment: Linux > Reporter: Janne Siren > Assignee: Emmanuel Lecharny > Priority: Critical > Original Estimate: 2h > Remaining Estimate: 2h > > Qt4 (4.4.3) QHttp class sends HTTP/POST command with HTTP header which has > "content-length" field name in small letters. HTTP header parsing > functionality in MINA Example does not accept these POST commands as it > expects case-sensitive field name "Content-Length". MINA Example HTTP header > parser functionality incorrectly drops these POST messages send by Qt4 QHttp > class although those messages are fully compatible with rfc2616. Cut from > rfc2616 (4.2 Message Headers): Field names are case-insensitive. > The problem (at least in MINA-1.1.0) is in > org.apache.mina.example.httpserver.codec.HttpRequestDecoder.java: > private static final byte[] CONTENT_LENGTH = new String( "Content-Length:" ) > .getBytes(); > ... > boolean found = false; > for( int j = 0; j < CONTENT_LENGTH.length; j++ ) > { > if( in.get( i + j ) != CONTENT_LENGTH[ > j ] ) > { > found = false; > break; > } > found = true; > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.