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;
|
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.DefaultFullHttpRequest;
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpMessage;
|
import io.netty.handler.codec.http.FullHttpMessage;
|
||||||
@ -47,6 +35,19 @@ import java.net.URI;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
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
|
* Provides utility methods and constants for the HTTP/2 to HTTP conversion
|
||||||
*/
|
*/
|
||||||
@ -288,7 +289,7 @@ public final class HttpConversionUtil {
|
|||||||
* </ul>
|
* </ul>
|
||||||
* {@link ExtensionHeaderNames#PATH} is ignored and instead extracted from the {@code Request-Line}.
|
* {@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();
|
HttpHeaders inHeaders = in.headers();
|
||||||
final Http2Headers out = new DefaultHttp2Headers(validateHeaders, inHeaders.size());
|
final Http2Headers out = new DefaultHttp2Headers(validateHeaders, inHeaders.size());
|
||||||
if (in instanceof HttpRequest) {
|
if (in instanceof HttpRequest) {
|
||||||
@ -313,7 +314,7 @@ public final class HttpConversionUtil {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders) throws Exception {
|
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders) {
|
||||||
if (inHeaders.isEmpty()) {
|
if (inHeaders.isEmpty()) {
|
||||||
return EmptyHttp2Headers.INSTANCE;
|
return EmptyHttp2Headers.INSTANCE;
|
||||||
}
|
}
|
||||||
@ -323,7 +324,7 @@ public final class HttpConversionUtil {
|
|||||||
return out;
|
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();
|
Iterator<Entry<CharSequence, CharSequence>> iter = inHeaders.iteratorCharSequence();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Entry<CharSequence, CharSequence> entry = iter.next();
|
Entry<CharSequence, CharSequence> entry = iter.next();
|
||||||
@ -339,21 +340,27 @@ public final class HttpConversionUtil {
|
|||||||
AsciiString value = AsciiString.of(entry.getValue());
|
AsciiString value = AsciiString.of(entry.getValue());
|
||||||
// split up cookies to allow for better compression
|
// split up cookies to allow for better compression
|
||||||
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
||||||
int index = value.forEachByte(FIND_SEMI_COLON);
|
try {
|
||||||
if (index != -1) {
|
int index = value.forEachByte(FIND_SEMI_COLON);
|
||||||
int start = 0;
|
if (index != -1) {
|
||||||
do {
|
int start = 0;
|
||||||
out.add(HttpHeaderNames.COOKIE, value.subSequence(start, index, false));
|
do {
|
||||||
// skip 2 characters "; " (see https://tools.ietf.org/html/rfc6265#section-4.2.1)
|
out.add(HttpHeaderNames.COOKIE, value.subSequence(start, index, false));
|
||||||
start = index + 2;
|
// skip 2 characters "; " (see https://tools.ietf.org/html/rfc6265#section-4.2.1)
|
||||||
} while (start < value.length() &&
|
start = index + 2;
|
||||||
(index = value.forEachByte(start, value.length() - start, FIND_SEMI_COLON)) != -1);
|
} while (start < value.length() &&
|
||||||
if (start >= value.length()) {
|
(index = value.forEachByte(start, value.length() - start, FIND_SEMI_COLON)) != -1);
|
||||||
throw new IllegalArgumentException("cookie value is of unexpected format: " + value);
|
if (start >= value.length()) {
|
||||||
|
throw new IllegalArgumentException("cookie value is of unexpected format: " + value);
|
||||||
|
}
|
||||||
|
out.add(HttpHeaderNames.COOKIE, value.subSequence(start, value.length(), false));
|
||||||
|
} else {
|
||||||
|
out.add(HttpHeaderNames.COOKIE, value);
|
||||||
}
|
}
|
||||||
out.add(HttpHeaderNames.COOKIE, value.subSequence(start, value.length(), false));
|
} catch (Exception e) {
|
||||||
} else {
|
// This is not expect to happen because FIND_SEMI_COLON never throws but must be caught
|
||||||
out.add(HttpHeaderNames.COOKIE, value);
|
// because of the ByteProcessor interface.
|
||||||
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.add(aName, entry.getValue());
|
out.add(aName, entry.getValue());
|
||||||
|
@ -80,12 +80,17 @@ public interface ByteProcessor {
|
|||||||
*/
|
*/
|
||||||
ByteProcessor FIND_NON_LF = new IndexNotOfProcessor((byte) '\n');
|
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')}.
|
* Aborts on a {@code CR ('\r')} or a {@code LF ('\n')}.
|
||||||
*/
|
*/
|
||||||
ByteProcessor FIND_CRLF = new ByteProcessor() {
|
ByteProcessor FIND_CRLF = new ByteProcessor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean process(byte value) throws Exception {
|
public boolean process(byte value) {
|
||||||
return value != '\r' && value != '\n';
|
return value != '\r' && value != '\n';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -95,7 +100,7 @@ public interface ByteProcessor {
|
|||||||
*/
|
*/
|
||||||
ByteProcessor FIND_NON_CRLF = new ByteProcessor() {
|
ByteProcessor FIND_NON_CRLF = new ByteProcessor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean process(byte value) throws Exception {
|
public boolean process(byte value) {
|
||||||
return value == '\r' || value == '\n';
|
return value == '\r' || value == '\n';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -105,7 +110,7 @@ public interface ByteProcessor {
|
|||||||
*/
|
*/
|
||||||
ByteProcessor FIND_LINEAR_WHITESPACE = new ByteProcessor() {
|
ByteProcessor FIND_LINEAR_WHITESPACE = new ByteProcessor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean process(byte value) throws Exception {
|
public boolean process(byte value) {
|
||||||
return value != ' ' && value != '\t';
|
return value != ' ' && value != '\t';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -115,21 +120,11 @@ public interface ByteProcessor {
|
|||||||
*/
|
*/
|
||||||
ByteProcessor FIND_NON_LINEAR_WHITESPACE = new ByteProcessor() {
|
ByteProcessor FIND_NON_LINEAR_WHITESPACE = new ByteProcessor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean process(byte value) throws Exception {
|
public boolean process(byte value) {
|
||||||
return value == ' ' || value == '\t';
|
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.
|
* @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.
|
* {@code false} if the processor wants to stop handling bytes and abort the loop.
|
||||||
|
Loading…
Reference in New Issue
Block a user