HttpConversionUtil remove throws from method signature
Motivation: HttpConversionUtil.toHttp2Headers currently has a throws Exception as part of the signature. This comes from the signature of ByteProcessor.process, but is not necessary because the ByteProcessor used does not throw. Modifications: - Remove throws Exception from the signature of HttpConversionUtil.toHttp2Headers. Result: HttpConversionUtil.toHttp2Headers interface does not propagate a throws Exception when it is used.
This commit is contained in:
parent
f7c83c8565
commit
7dba13f276
@ -14,18 +14,6 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http2;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpScheme.HTTP;
|
||||
import static io.netty.handler.codec.http.HttpScheme.HTTPS;
|
||||
import static io.netty.handler.codec.http.HttpUtil.isAsteriskForm;
|
||||
import static io.netty.handler.codec.http.HttpUtil.isOriginForm;
|
||||
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
||||
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
|
||||
import static io.netty.handler.codec.http2.Http2Exception.streamError;
|
||||
import static io.netty.util.AsciiString.EMPTY_STRING;
|
||||
import static io.netty.util.ByteProcessor.FIND_SEMI_COLON;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
||||
import static io.netty.util.internal.StringUtil.isNullOrEmpty;
|
||||
import static io.netty.util.internal.StringUtil.length;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpRequest;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||
import io.netty.handler.codec.http.FullHttpMessage;
|
||||
@ -47,6 +35,19 @@ import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpScheme.HTTP;
|
||||
import static io.netty.handler.codec.http.HttpScheme.HTTPS;
|
||||
import static io.netty.handler.codec.http.HttpUtil.isAsteriskForm;
|
||||
import static io.netty.handler.codec.http.HttpUtil.isOriginForm;
|
||||
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
||||
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
|
||||
import static io.netty.handler.codec.http2.Http2Exception.streamError;
|
||||
import static io.netty.util.AsciiString.EMPTY_STRING;
|
||||
import static io.netty.util.ByteProcessor.FIND_SEMI_COLON;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
||||
import static io.netty.util.internal.StringUtil.isNullOrEmpty;
|
||||
import static io.netty.util.internal.StringUtil.length;
|
||||
|
||||
/**
|
||||
* Provides utility methods and constants for the HTTP/2 to HTTP conversion
|
||||
*/
|
||||
@ -288,7 +289,7 @@ public final class HttpConversionUtil {
|
||||
* </ul>
|
||||
* {@link ExtensionHeaderNames#PATH} is ignored and instead extracted from the {@code Request-Line}.
|
||||
*/
|
||||
public static Http2Headers toHttp2Headers(HttpMessage in, boolean validateHeaders) throws Exception {
|
||||
public static Http2Headers toHttp2Headers(HttpMessage in, boolean validateHeaders) {
|
||||
HttpHeaders inHeaders = in.headers();
|
||||
final Http2Headers out = new DefaultHttp2Headers(validateHeaders, inHeaders.size());
|
||||
if (in instanceof HttpRequest) {
|
||||
@ -313,7 +314,7 @@ public final class HttpConversionUtil {
|
||||
return out;
|
||||
}
|
||||
|
||||
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders) throws Exception {
|
||||
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders) {
|
||||
if (inHeaders.isEmpty()) {
|
||||
return EmptyHttp2Headers.INSTANCE;
|
||||
}
|
||||
@ -323,7 +324,7 @@ public final class HttpConversionUtil {
|
||||
return out;
|
||||
}
|
||||
|
||||
public static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out) throws Exception {
|
||||
public static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out) {
|
||||
Iterator<Entry<CharSequence, CharSequence>> iter = inHeaders.iteratorCharSequence();
|
||||
while (iter.hasNext()) {
|
||||
Entry<CharSequence, CharSequence> entry = iter.next();
|
||||
@ -339,6 +340,7 @@ public final class HttpConversionUtil {
|
||||
AsciiString value = AsciiString.of(entry.getValue());
|
||||
// split up cookies to allow for better compression
|
||||
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
||||
try {
|
||||
int index = value.forEachByte(FIND_SEMI_COLON);
|
||||
if (index != -1) {
|
||||
int start = 0;
|
||||
@ -355,6 +357,11 @@ public final class HttpConversionUtil {
|
||||
} else {
|
||||
out.add(HttpHeaderNames.COOKIE, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// This is not expect to happen because FIND_SEMI_COLON never throws but must be caught
|
||||
// because of the ByteProcessor interface.
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
} else {
|
||||
out.add(aName, entry.getValue());
|
||||
}
|
||||
|
@ -80,12 +80,17 @@ public interface ByteProcessor {
|
||||
*/
|
||||
ByteProcessor FIND_NON_LF = new IndexNotOfProcessor((byte) '\n');
|
||||
|
||||
/**
|
||||
* Aborts on a {@code CR (';')}.
|
||||
*/
|
||||
ByteProcessor FIND_SEMI_COLON = new IndexOfProcessor((byte) ';');
|
||||
|
||||
/**
|
||||
* Aborts on a {@code CR ('\r')} or a {@code LF ('\n')}.
|
||||
*/
|
||||
ByteProcessor FIND_CRLF = new ByteProcessor() {
|
||||
@Override
|
||||
public boolean process(byte value) throws Exception {
|
||||
public boolean process(byte value) {
|
||||
return value != '\r' && value != '\n';
|
||||
}
|
||||
};
|
||||
@ -95,7 +100,7 @@ public interface ByteProcessor {
|
||||
*/
|
||||
ByteProcessor FIND_NON_CRLF = new ByteProcessor() {
|
||||
@Override
|
||||
public boolean process(byte value) throws Exception {
|
||||
public boolean process(byte value) {
|
||||
return value == '\r' || value == '\n';
|
||||
}
|
||||
};
|
||||
@ -105,7 +110,7 @@ public interface ByteProcessor {
|
||||
*/
|
||||
ByteProcessor FIND_LINEAR_WHITESPACE = new ByteProcessor() {
|
||||
@Override
|
||||
public boolean process(byte value) throws Exception {
|
||||
public boolean process(byte value) {
|
||||
return value != ' ' && value != '\t';
|
||||
}
|
||||
};
|
||||
@ -115,21 +120,11 @@ public interface ByteProcessor {
|
||||
*/
|
||||
ByteProcessor FIND_NON_LINEAR_WHITESPACE = new ByteProcessor() {
|
||||
@Override
|
||||
public boolean process(byte value) throws Exception {
|
||||
public boolean process(byte value) {
|
||||
return value == ' ' || value == '\t';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Aborts on a {@code CR (';')}.
|
||||
*/
|
||||
ByteProcessor FIND_SEMI_COLON = new ByteProcessor() {
|
||||
@Override
|
||||
public boolean process(byte value) throws Exception {
|
||||
return value != ';';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {@code true} if the processor wants to continue the loop and handle the next byte in the buffer.
|
||||
* {@code false} if the processor wants to stop handling bytes and abort the loop.
|
||||
|
Loading…
Reference in New Issue
Block a user