Allow to override how headers are encoded
Motivation: Even if its against the HTTP RFC there are situations where it may be useful to use other chars then US_ASCII in the headers. We should allow to make it possible by allow the user to override the how headers are encoded. Modifications: - Add encodeHeaders(...) method and so allow to override it. Result: It's now possible to encode headers with other charset then US_ASCII by just extend the encoder and override the encodeHeaders(...) method.
This commit is contained in:
parent
e427fc56a0
commit
1ed8a120c1
@ -70,7 +70,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
|
|||||||
buf = ctx.alloc().buffer();
|
buf = ctx.alloc().buffer();
|
||||||
// Encode the message.
|
// Encode the message.
|
||||||
encodeInitialLine(buf, m);
|
encodeInitialLine(buf, m);
|
||||||
m.headers().forEachEntry(new HttpHeadersEncoder(buf));
|
encodeHeaders(m.headers(), buf);
|
||||||
buf.writeBytes(CRLF);
|
buf.writeBytes(CRLF);
|
||||||
state = HttpHeaderUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK;
|
state = HttpHeaderUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK;
|
||||||
}
|
}
|
||||||
@ -133,6 +133,13 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode the {@link HttpHeaders} into a {@link ByteBuf}.
|
||||||
|
*/
|
||||||
|
protected void encodeHeaders(HttpHeaders headers, ByteBuf buf) throws Exception {
|
||||||
|
headers.forEachEntry(new HttpHeadersEncoder(buf));
|
||||||
|
}
|
||||||
|
|
||||||
private void encodeChunkedContent(ChannelHandlerContext ctx, Object msg, long contentLength, List<Object> out) {
|
private void encodeChunkedContent(ChannelHandlerContext ctx, Object msg, long contentLength, List<Object> out) {
|
||||||
if (contentLength > 0) {
|
if (contentLength > 0) {
|
||||||
byte[] length = Long.toHexString(contentLength).getBytes(CharsetUtil.US_ASCII);
|
byte[] length = Long.toHexString(contentLength).getBytes(CharsetUtil.US_ASCII);
|
||||||
@ -152,7 +159,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
|
|||||||
ByteBuf buf = ctx.alloc().buffer();
|
ByteBuf buf = ctx.alloc().buffer();
|
||||||
buf.writeBytes(ZERO_CRLF);
|
buf.writeBytes(ZERO_CRLF);
|
||||||
try {
|
try {
|
||||||
headers.forEachEntry(new HttpHeadersEncoder(buf));
|
encodeHeaders(headers, buf);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
buf.release();
|
buf.release();
|
||||||
PlatformDependent.throwException(ex);
|
PlatformDependent.throwException(ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user