Skip to content

Commit e751231

Browse files
Brendt LucasScottmitch
authored andcommitted
[netty#4185] SpdyHttpEncoder fails to convert HttpResponse to SpdyFrame
Motivation: When SpdyHttpEncoder attempts to create an SpdyHeadersFrame from a HttpResponse an IllegalArgumentException is thrown if the original HttpResponse contains a header that includes uppercase characters. The IllegalArgumentException is thrown due to the additional validation check introduced by netty#4047. Previous versions of the SPDY codec would handle this by converting the HTTP header name to lowercase before adding the header to the SpdyHeadersFrame. Modifications: Convert the header name to lowercase before adding it to SpdyHeaders Result: SpdyHttpEncoder can now convert a valid HttpResponse into a valid SpdyFrame
1 parent a26d2d7 commit e751231

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.handler.codec.http.HttpRequest;
2828
import io.netty.handler.codec.http.HttpResponse;
2929
import io.netty.handler.codec.http.LastHttpContent;
30+
import io.netty.util.AsciiString;
3031

3132
import java.util.List;
3233
import java.util.Map;
@@ -172,7 +173,7 @@ protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> ou
172173
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(currentStreamId);
173174
spdyHeadersFrame.setLast(true);
174175
for (Map.Entry<CharSequence, CharSequence> entry: trailers) {
175-
spdyHeadersFrame.headers().add(entry.getKey(), entry.getValue());
176+
spdyHeadersFrame.headers().add(AsciiString.of(entry.getKey()).toLowerCase(), entry.getValue());
176177
}
177178

178179
// Write DATA frame and append HEADERS frame
@@ -233,7 +234,7 @@ private SpdySynStreamFrame createSynStreamFrame(HttpRequest httpRequest) throws
233234

234235
// Transfer the remaining HTTP headers
235236
for (Map.Entry<CharSequence, CharSequence> entry: httpHeaders) {
236-
frameHeaders.add(entry.getKey(), entry.getValue());
237+
frameHeaders.add(AsciiString.of(entry.getKey()).toLowerCase(), entry.getValue());
237238
}
238239
currentStreamId = spdySynStreamFrame.streamId();
239240
if (associatedToStreamId == 0) {
@@ -272,7 +273,7 @@ private SpdyHeadersFrame createHeadersFrame(HttpResponse httpResponse) throws Ex
272273

273274
// Transfer the remaining HTTP headers
274275
for (Map.Entry<CharSequence, CharSequence> entry: httpHeaders) {
275-
spdyHeadersFrame.headers().add(entry.getKey(), entry.getValue());
276+
spdyHeadersFrame.headers().add(AsciiString.of(entry.getKey()).toLowerCase(), entry.getValue());
276277
}
277278

278279
currentStreamId = streamId;

0 commit comments

Comments
 (0)