Overall cleanup of 2b191fe6e9
This commit is contained in:
parent
2b191fe6e9
commit
1be42ca6e4
@ -220,41 +220,41 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
State nextState = readHeaders(buffer);
|
State nextState = readHeaders(buffer);
|
||||||
checkpoint(nextState);
|
checkpoint(nextState);
|
||||||
switch (nextState) {
|
switch (nextState) {
|
||||||
case SKIP_CONTROL_CHARS:
|
case SKIP_CONTROL_CHARS:
|
||||||
// fast-path
|
// fast-path
|
||||||
// No content is expected.
|
// No content is expected.
|
||||||
|
out.add(message);
|
||||||
|
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
|
resetNow();
|
||||||
|
return;
|
||||||
|
case READ_CHUNK_SIZE:
|
||||||
|
if (!chunkedSupported) {
|
||||||
|
throw new IllegalArgumentException("Chunked messages not supported");
|
||||||
|
}
|
||||||
|
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
|
||||||
|
out.add(message);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
long contentLength = contentLength();
|
||||||
|
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
||||||
out.add(message);
|
out.add(message);
|
||||||
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
resetNow();
|
resetNow();
|
||||||
return;
|
return;
|
||||||
case READ_CHUNK_SIZE:
|
}
|
||||||
if (!chunkedSupported) {
|
|
||||||
throw new IllegalArgumentException("Chunked messages not supported");
|
|
||||||
}
|
|
||||||
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
|
|
||||||
out.add(message);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
long contentLength = contentLength();
|
|
||||||
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
|
|
||||||
out.add(message);
|
|
||||||
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
|
||||||
resetNow();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert nextState == State.READ_FIXED_LENGTH_CONTENT ||
|
assert nextState == State.READ_FIXED_LENGTH_CONTENT ||
|
||||||
nextState == State.READ_VARIABLE_LENGTH_CONTENT;
|
nextState == State.READ_VARIABLE_LENGTH_CONTENT;
|
||||||
|
|
||||||
out.add(message);
|
out.add(message);
|
||||||
|
|
||||||
if (nextState == State.READ_FIXED_LENGTH_CONTENT) {
|
if (nextState == State.READ_FIXED_LENGTH_CONTENT) {
|
||||||
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT state reads data chunk by chunk.
|
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT state reads data chunk by chunk.
|
||||||
chunkSize = contentLength;
|
chunkSize = contentLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We return here, this forces decode to be called again where we will decode the content
|
// We return here, this forces decode to be called again where we will decode the content
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
out.add(invalidMessage(e));
|
out.add(invalidMessage(e));
|
||||||
@ -385,7 +385,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
// Handle the last unfinished message.
|
// Handle the last unfinished message.
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
boolean chunked = HttpHeaders.isTransferEncodingChunked(message);
|
boolean chunked = HttpHeaders.isTransferEncodingChunked(message);
|
||||||
if (state() == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) {
|
if (state() == State.READ_VARIABLE_LENGTH_CONTENT && !in.isReadable() && !chunked) {
|
||||||
// End of connection.
|
// End of connection.
|
||||||
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
reset();
|
reset();
|
||||||
@ -502,7 +502,11 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
do {
|
do {
|
||||||
char firstChar = line.charAt(0);
|
char firstChar = line.charAt(0);
|
||||||
if (name != null && (firstChar == ' ' || firstChar == '\t')) {
|
if (name != null && (firstChar == ' ' || firstChar == '\t')) {
|
||||||
value = value.toString() + ' ' + line.toString().trim();
|
StringBuilder buf = new StringBuilder(value.length() + line.length() + 1);
|
||||||
|
buf.append(value);
|
||||||
|
buf.append(' ');
|
||||||
|
buf.append(line.toString().trim());
|
||||||
|
value = buf.toString();
|
||||||
} else {
|
} else {
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
headers.add(name, value);
|
headers.add(name, value);
|
||||||
@ -568,8 +572,8 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
splitHeader(line);
|
splitHeader(line);
|
||||||
CharSequence headerName = name;
|
CharSequence headerName = name;
|
||||||
if (!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.CONTENT_LENGTH) &&
|
if (!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.CONTENT_LENGTH) &&
|
||||||
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRANSFER_ENCODING) &&
|
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRANSFER_ENCODING) &&
|
||||||
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRAILER)) {
|
!AsciiString.equalsIgnoreCase(headerName, HttpHeaders.Names.TRAILER)) {
|
||||||
trailer.trailingHeaders().add(headerName, value);
|
trailer.trailingHeaders().add(headerName, value);
|
||||||
}
|
}
|
||||||
lastHeader = name;
|
lastHeader = name;
|
||||||
@ -736,9 +740,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected TooLongFrameException newException(int maxLength) {
|
protected TooLongFrameException newException(int maxLength) {
|
||||||
return new TooLongFrameException(
|
return new TooLongFrameException("HTTP header is larger than " + maxLength + " bytes.");
|
||||||
"HTTP header is larger than " + maxLength +
|
|
||||||
" bytes.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -756,9 +758,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TooLongFrameException newException(int maxLength) {
|
protected TooLongFrameException newException(int maxLength) {
|
||||||
return new TooLongFrameException(
|
return new TooLongFrameException("An HTTP line is larger than " + maxLength + " bytes.");
|
||||||
"An HTTP line is larger than " + maxLength +
|
|
||||||
" bytes.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user