414640 HTTP header value encoding

fixed issues with merge
This commit is contained in:
Greg Wilkins 2013-08-09 16:31:11 +10:00
parent 8ce87ffafc
commit 009113aacb
2 changed files with 19 additions and 21 deletions

View File

@ -302,7 +302,7 @@ public class HttpParser
} }
// Only LF or TAB acceptable special characters // Only LF or TAB acceptable special characters
else if (!(ch==HttpTokens.LINE_FEED || ch==HttpTokens.TAB)) else if (!(ch==HttpTokens.LINE_FEED || ch==HttpTokens.TAB))
throw new BadMessage(); throw new BadMessage("Illegal character");
} }
return ch; return ch;
@ -350,6 +350,8 @@ public class HttpParser
} }
else if (ch==0) else if (ch==0)
break; break;
else if (ch<0)
throw new BadMessage();
} }
return false; return false;
} }
@ -415,10 +417,8 @@ public class HttpParser
_methodString=method.asString(); _methodString=method.asString();
setState(State.SPACE1); setState(State.SPACE1);
} }
else if (ch < HttpTokens.SPACE && ch>=0) else if (ch < HttpTokens.SPACE)
{ throw new BadMessage(ch<0?"Illegal character":"No URI");
throw new BadMessage(HttpStatus.BAD_REQUEST_400,"No URI");
}
else else
_string.append((char)ch); _string.append((char)ch);
break; break;
@ -429,15 +429,11 @@ public class HttpParser
String version=takeString(); String version=takeString();
_version=HttpVersion.CACHE.get(version); _version=HttpVersion.CACHE.get(version);
if (_version==null) if (_version==null)
{
throw new BadMessage(HttpStatus.BAD_REQUEST_400,"Unknown Version"); throw new BadMessage(HttpStatus.BAD_REQUEST_400,"Unknown Version");
}
setState(State.SPACE1); setState(State.SPACE1);
} }
else if (ch < HttpTokens.SPACE && ch>=0) else if (ch < HttpTokens.SPACE)
{ throw new BadMessage(ch<0?"Illegal character":"No Status");
throw new BadMessage(HttpStatus.BAD_REQUEST_400,"No Status");
}
else else
_string.append((char)ch); _string.append((char)ch);
break; break;
@ -508,7 +504,7 @@ public class HttpParser
} }
else else
{ {
throw new IllegalStateException(); throw new BadMessage();
} }
break; break;
@ -541,7 +537,7 @@ public class HttpParser
break; break;
case SPACE2: case SPACE2:
if (ch > HttpTokens.SPACE || ch<0) if (ch > HttpTokens.SPACE)
{ {
_string.setLength(0); _string.setLength(0);
_string.append((char)ch); _string.append((char)ch);
@ -601,6 +597,8 @@ public class HttpParser
handle=_handler.messageComplete()||handle; handle=_handler.messageComplete()||handle;
} }
} }
else if (ch<0)
throw new BadMessage();
break; break;
case REQUEST_VERSION: case REQUEST_VERSION:
@ -624,8 +622,10 @@ public class HttpParser
handle=_requestHandler.startRequest(_method,_methodString,_uri, _version)||handle; handle=_requestHandler.startRequest(_method,_methodString,_uri, _version)||handle;
continue; continue;
} }
else else if (ch>=HttpTokens.SPACE)
_string.append((char)ch); _string.append((char)ch);
else
throw new BadMessage();
break; break;
@ -638,12 +638,14 @@ public class HttpParser
handle=_responseHandler.startResponse(_version, _responseStatus, reason)||handle; handle=_responseHandler.startResponse(_version, _responseStatus, reason)||handle;
continue; continue;
} }
else else if (ch>=HttpTokens.SPACE)
{ {
_string.append((char)ch); _string.append((char)ch);
if (ch!=' '&&ch!='\t') if (ch!=' '&&ch!='\t')
_length=_string.length(); _length=_string.length();
} }
else
throw new BadMessage();
break; break;
default: default:
@ -1001,10 +1003,6 @@ public class HttpParser
break; break;
case HEADER_IN_NAME: case HEADER_IN_NAME:
if (ch<HttpTokens.SPACE)
{
}
if (ch<0) if (ch<0)
throw new BadMessage("Illegal character"); throw new BadMessage("Illegal character");
switch(ch) switch(ch)

View File

@ -363,7 +363,7 @@ public class HttpParserTest
assertEquals("HTTP/1.0", _versionOrReason); assertEquals("HTTP/1.0", _versionOrReason);
assertEquals("Header1", _hdr[0]); assertEquals("Header1", _hdr[0]);
assertEquals("\u00e6 \u00e6", _val[0]); assertEquals("\u00e6 \u00e6", _val[0]);
assertEquals(0, _h); assertEquals(0, _headers);
assertEquals(null,_bad); assertEquals(null,_bad);
} }