2012-05-31 09:37:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2012 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-31 09:37:27 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.handler.codec.spdy;
|
|
|
|
|
2012-06-07 07:52:33 +02:00
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
2012-05-31 09:37:27 +02:00
|
|
|
import io.netty.handler.codec.MessageToMessageEncoder;
|
|
|
|
import io.netty.handler.codec.UnsupportedMessageTypeException;
|
2013-07-19 22:03:18 +02:00
|
|
|
import io.netty.handler.codec.http.FullHttpMessage;
|
2013-01-14 16:52:30 +01:00
|
|
|
import io.netty.handler.codec.http.HttpContent;
|
2014-10-31 08:48:28 +01:00
|
|
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
2012-05-31 09:37:27 +02:00
|
|
|
import io.netty.handler.codec.http.HttpHeaders;
|
2013-01-16 05:22:50 +01:00
|
|
|
import io.netty.handler.codec.http.HttpMessage;
|
|
|
|
import io.netty.handler.codec.http.HttpObject;
|
2012-05-31 09:37:27 +02:00
|
|
|
import io.netty.handler.codec.http.HttpRequest;
|
2013-01-16 05:22:50 +01:00
|
|
|
import io.netty.handler.codec.http.HttpResponse;
|
2013-01-14 16:52:30 +01:00
|
|
|
import io.netty.handler.codec.http.LastHttpContent;
|
2015-09-04 19:08:03 +02:00
|
|
|
import io.netty.util.AsciiString;
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2015-09-04 19:08:03 +02:00
|
|
|
import java.util.Iterator;
|
2012-05-31 09:37:27 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2015-09-04 19:08:03 +02:00
|
|
|
import java.util.Map.Entry;
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
/**
|
2013-01-16 05:22:50 +01:00
|
|
|
* Encodes {@link HttpRequest}s, {@link HttpResponse}s, and {@link HttpContent}s
|
2012-05-31 09:37:27 +02:00
|
|
|
* into {@link SpdySynStreamFrame}s and {@link SpdySynReplyFrame}s.
|
|
|
|
*
|
|
|
|
* <h3>Request Annotations</h3>
|
|
|
|
*
|
2013-01-16 05:22:50 +01:00
|
|
|
* SPDY specific headers must be added to {@link HttpRequest}s:
|
2012-05-31 09:37:27 +02:00
|
|
|
* <table border=1>
|
|
|
|
* <tr>
|
|
|
|
* <th>Header Name</th><th>Header Value</th>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
|
|
|
* <td>The Stream-ID for this request.
|
|
|
|
* Stream-IDs must be odd, positive integers, and must increase monotonically.</td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Priority"}</td>
|
|
|
|
* <td>The priority value for this request.
|
|
|
|
* The priority should be between 0 and 7 inclusive.
|
|
|
|
* 0 represents the highest priority and 7 represents the lowest.
|
|
|
|
* This header is optional and defaults to 0.</td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
|
|
|
*
|
|
|
|
* <h3>Response Annotations</h3>
|
|
|
|
*
|
2013-01-16 05:22:50 +01:00
|
|
|
* SPDY specific headers must be added to {@link HttpResponse}s:
|
2012-05-31 09:37:27 +02:00
|
|
|
* <table border=1>
|
|
|
|
* <tr>
|
|
|
|
* <th>Header Name</th><th>Header Value</th>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
|
|
|
* <td>The Stream-ID of the request corresponding to this response.</td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
|
|
|
*
|
|
|
|
* <h3>Pushed Resource Annotations</h3>
|
|
|
|
*
|
2015-01-10 19:53:54 +01:00
|
|
|
* SPDY specific headers must be added to pushed {@link HttpRequest}s:
|
2012-05-31 09:37:27 +02:00
|
|
|
* <table border=1>
|
|
|
|
* <tr>
|
|
|
|
* <th>Header Name</th><th>Header Value</th>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Stream-ID"}</td>
|
|
|
|
* <td>The Stream-ID for this resource.
|
|
|
|
* Stream-IDs must be even, positive integers, and must increase monotonically.</td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Associated-To-Stream-ID"}</td>
|
|
|
|
* <td>The Stream-ID of the request that initiated this pushed resource.</td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td>{@code "X-SPDY-Priority"}</td>
|
|
|
|
* <td>The priority value for this resource.
|
|
|
|
* The priority should be between 0 and 7 inclusive.
|
|
|
|
* 0 represents the highest priority and 7 represents the lowest.
|
|
|
|
* This header is optional and defaults to 0.</td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
|
|
|
*
|
|
|
|
* <h3>Required Annotations</h3>
|
|
|
|
*
|
|
|
|
* SPDY requires that all Requests and Pushed Resources contain
|
|
|
|
* an HTTP "Host" header.
|
|
|
|
*
|
|
|
|
* <h3>Optional Annotations</h3>
|
|
|
|
*
|
|
|
|
* Requests and Pushed Resources must contain a SPDY scheme header.
|
|
|
|
* This can be set via the {@code "X-SPDY-Scheme"} header but otherwise
|
|
|
|
* defaults to "https" as that is the most common SPDY deployment.
|
|
|
|
*
|
|
|
|
* <h3>Chunked Content</h3>
|
|
|
|
*
|
2013-01-14 16:52:30 +01:00
|
|
|
* This encoder associates all {@link HttpContent}s that it receives
|
2013-01-16 05:22:50 +01:00
|
|
|
* with the most recently received 'chunked' {@link HttpRequest}
|
|
|
|
* or {@link HttpResponse}.
|
2012-05-31 09:37:27 +02:00
|
|
|
*
|
|
|
|
* <h3>Pushed Resources</h3>
|
|
|
|
*
|
|
|
|
* All pushed resources should be sent before sending the response
|
|
|
|
* that corresponds to the initial request.
|
|
|
|
*/
|
2013-02-06 04:55:42 +01:00
|
|
|
public class SpdyHttpEncoder extends MessageToMessageEncoder<HttpObject> {
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2013-06-13 07:43:39 +02:00
|
|
|
private int currentStreamId;
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2015-09-04 23:17:29 +02:00
|
|
|
private final boolean validateHeaders;
|
|
|
|
private final boolean headersToLowerCase;
|
|
|
|
|
2012-05-31 09:37:27 +02:00
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*
|
|
|
|
* @param version the protocol version
|
|
|
|
*/
|
2013-09-27 19:48:16 +02:00
|
|
|
public SpdyHttpEncoder(SpdyVersion version) {
|
2015-09-04 23:17:29 +02:00
|
|
|
this(version, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*
|
|
|
|
* @param version the protocol version
|
|
|
|
* @param headersToLowerCase convert header names to lowercase. In a controlled environment,
|
|
|
|
* one can disable the conversion.
|
|
|
|
* @param validateHeaders validate the header names and values when adding them to the {@link SpdyHeaders}
|
|
|
|
*/
|
|
|
|
public SpdyHttpEncoder(SpdyVersion version, boolean headersToLowerCase, boolean validateHeaders) {
|
2013-09-27 19:48:16 +02:00
|
|
|
if (version == null) {
|
|
|
|
throw new NullPointerException("version");
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
2015-09-04 23:17:29 +02:00
|
|
|
this.headersToLowerCase = headersToLowerCase;
|
|
|
|
this.validateHeaders = validateHeaders;
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Remove MessageList from public API and change ChannelInbound/OutboundHandler accordingly
I must admit MesageList was pain in the ass. Instead of forcing a
handler always loop over the list of messages, this commit splits
messageReceived(ctx, list) into two event handlers:
- messageReceived(ctx, msg)
- mmessageReceivedLast(ctx)
When Netty reads one or more messages, messageReceived(ctx, msg) event
is triggered for each message. Once the current read operation is
finished, messageReceivedLast() is triggered to tell the handler that
the last messageReceived() was the last message in the current batch.
Similarly, for outbound, write(ctx, list) has been split into two:
- write(ctx, msg)
- flush(ctx, promise)
Instead of writing a list of message with a promise, a user is now
supposed to call write(msg) multiple times and then call flush() to
actually flush the buffered messages.
Please note that write() doesn't have a promise with it. You must call
flush() to get notified on completion. (or you can use writeAndFlush())
Other changes:
- Because MessageList is completely hidden, codec framework uses
List<Object> instead of MessageList as an output parameter.
2013-07-08 12:03:40 +02:00
|
|
|
protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception {
|
2013-02-27 23:23:36 +01:00
|
|
|
|
|
|
|
boolean valid = false;
|
2013-07-19 22:03:18 +02:00
|
|
|
boolean last = false;
|
2013-02-27 23:23:36 +01:00
|
|
|
|
2013-01-16 05:22:50 +01:00
|
|
|
if (msg instanceof HttpRequest) {
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2013-01-16 05:22:50 +01:00
|
|
|
HttpRequest httpRequest = (HttpRequest) msg;
|
2012-05-31 09:37:27 +02:00
|
|
|
SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpRequest);
|
|
|
|
out.add(spdySynStreamFrame);
|
2013-02-27 23:23:36 +01:00
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
last = spdySynStreamFrame.isLast() || spdySynStreamFrame.isUnidirectional();
|
2013-02-27 23:23:36 +01:00
|
|
|
valid = true;
|
2013-01-14 16:52:30 +01:00
|
|
|
}
|
2013-01-16 05:22:50 +01:00
|
|
|
if (msg instanceof HttpResponse) {
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2013-01-16 05:22:50 +01:00
|
|
|
HttpResponse httpResponse = (HttpResponse) msg;
|
2015-01-10 19:53:54 +01:00
|
|
|
SpdyHeadersFrame spdyHeadersFrame = createHeadersFrame(httpResponse);
|
|
|
|
out.add(spdyHeadersFrame);
|
2013-02-27 23:23:36 +01:00
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
last = spdyHeadersFrame.isLast();
|
2013-02-27 23:23:36 +01:00
|
|
|
valid = true;
|
2013-01-14 16:52:30 +01:00
|
|
|
}
|
2013-07-19 22:03:18 +02:00
|
|
|
if (msg instanceof HttpContent && !last) {
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2013-01-14 16:52:30 +01:00
|
|
|
HttpContent chunk = (HttpContent) msg;
|
2013-02-10 05:31:31 +01:00
|
|
|
|
2013-05-01 10:04:43 +02:00
|
|
|
chunk.content().retain();
|
|
|
|
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(currentStreamId, chunk.content());
|
2013-01-14 16:52:30 +01:00
|
|
|
if (chunk instanceof LastHttpContent) {
|
|
|
|
LastHttpContent trailer = (LastHttpContent) chunk;
|
2013-10-11 17:12:08 +02:00
|
|
|
HttpHeaders trailers = trailer.trailingHeaders();
|
2012-05-31 09:37:27 +02:00
|
|
|
if (trailers.isEmpty()) {
|
2015-01-10 19:53:54 +01:00
|
|
|
spdyDataFrame.setLast(true);
|
2012-05-31 09:37:27 +02:00
|
|
|
out.add(spdyDataFrame);
|
|
|
|
} else {
|
|
|
|
// Create SPDY HEADERS frame out of trailers
|
2015-09-04 23:17:29 +02:00
|
|
|
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(currentStreamId, validateHeaders);
|
2015-01-10 19:53:54 +01:00
|
|
|
spdyHeadersFrame.setLast(true);
|
2015-09-04 19:08:03 +02:00
|
|
|
Iterator<Entry<CharSequence, CharSequence>> itr = trailers.iteratorCharSequence();
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
Map.Entry<CharSequence, CharSequence> entry = itr.next();
|
2015-09-04 23:17:29 +02:00
|
|
|
final CharSequence headerName =
|
|
|
|
headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
|
|
|
|
spdyHeadersFrame.headers().add(headerName, entry.getValue());
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
// Write DATA frame and append HEADERS frame
|
2012-05-31 09:37:27 +02:00
|
|
|
out.add(spdyDataFrame);
|
2015-01-10 19:53:54 +01:00
|
|
|
out.add(spdyHeadersFrame);
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.add(spdyDataFrame);
|
|
|
|
}
|
2013-02-27 23:23:36 +01:00
|
|
|
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
2012-05-31 09:37:27 +02:00
|
|
|
throw new UnsupportedMessageTypeException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private SpdySynStreamFrame createSynStreamFrame(HttpRequest httpRequest) throws Exception {
|
|
|
|
// Get the Stream-ID, Associated-To-Stream-ID, Priority, and scheme from the headers
|
|
|
|
final HttpHeaders httpHeaders = httpRequest.headers();
|
2015-01-11 04:43:38 +01:00
|
|
|
int streamId = httpHeaders.getInt(SpdyHttpHeaders.Names.STREAM_ID);
|
|
|
|
int associatedToStreamId = httpHeaders.getInt(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID, 0);
|
|
|
|
byte priority = (byte) httpHeaders.getInt(SpdyHttpHeaders.Names.PRIORITY, 0);
|
|
|
|
CharSequence scheme = httpHeaders.get(SpdyHttpHeaders.Names.SCHEME);
|
|
|
|
httpHeaders.remove(SpdyHttpHeaders.Names.STREAM_ID);
|
|
|
|
httpHeaders.remove(SpdyHttpHeaders.Names.ASSOCIATED_TO_STREAM_ID);
|
|
|
|
httpHeaders.remove(SpdyHttpHeaders.Names.PRIORITY);
|
|
|
|
httpHeaders.remove(SpdyHttpHeaders.Names.SCHEME);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
|
|
|
|
// headers are not valid and MUST not be sent.
|
2014-10-31 08:48:28 +01:00
|
|
|
httpHeaders.remove(HttpHeaderNames.CONNECTION);
|
2014-06-14 10:33:34 +02:00
|
|
|
httpHeaders.remove("Keep-Alive");
|
|
|
|
httpHeaders.remove("Proxy-Connection");
|
2014-10-31 08:48:28 +01:00
|
|
|
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2012-06-08 12:28:12 +02:00
|
|
|
SpdySynStreamFrame spdySynStreamFrame =
|
2015-09-04 23:17:29 +02:00
|
|
|
new DefaultSpdySynStreamFrame(streamId, associatedToStreamId, priority, validateHeaders);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// Unfold the first line of the message into name/value pairs
|
2014-06-05 11:31:04 +02:00
|
|
|
SpdyHeaders frameHeaders = spdySynStreamFrame.headers();
|
2015-01-11 04:45:49 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.METHOD, httpRequest.method().name());
|
2015-01-11 04:43:38 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.PATH, httpRequest.uri());
|
2015-01-11 04:45:49 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpRequest.protocolVersion().text());
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// Replace the HTTP host header with the SPDY host header
|
2015-01-10 19:53:54 +01:00
|
|
|
CharSequence host = httpHeaders.get(HttpHeaderNames.HOST);
|
|
|
|
httpHeaders.remove(HttpHeaderNames.HOST);
|
2015-01-11 04:43:38 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.HOST, host);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// Set the SPDY scheme header
|
|
|
|
if (scheme == null) {
|
|
|
|
scheme = "https";
|
|
|
|
}
|
2015-01-11 04:43:38 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.SCHEME, scheme);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// Transfer the remaining HTTP headers
|
2015-09-04 19:08:03 +02:00
|
|
|
Iterator<Entry<CharSequence, CharSequence>> itr = httpHeaders.iteratorCharSequence();
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
Map.Entry<CharSequence, CharSequence> entry = itr.next();
|
2015-09-04 23:17:29 +02:00
|
|
|
final CharSequence headerName =
|
|
|
|
headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
|
|
|
|
frameHeaders.add(headerName, entry.getValue());
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
2014-06-24 10:39:46 +02:00
|
|
|
currentStreamId = spdySynStreamFrame.streamId();
|
2015-01-10 19:53:54 +01:00
|
|
|
if (associatedToStreamId == 0) {
|
|
|
|
spdySynStreamFrame.setLast(isLast(httpRequest));
|
|
|
|
} else {
|
|
|
|
spdySynStreamFrame.setUnidirectional(true);
|
|
|
|
}
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
return spdySynStreamFrame;
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private SpdyHeadersFrame createHeadersFrame(HttpResponse httpResponse) throws Exception {
|
2012-05-31 09:37:27 +02:00
|
|
|
// Get the Stream-ID from the headers
|
2014-06-14 10:33:34 +02:00
|
|
|
final HttpHeaders httpHeaders = httpResponse.headers();
|
2015-01-11 04:43:38 +01:00
|
|
|
int streamId = httpHeaders.getInt(SpdyHttpHeaders.Names.STREAM_ID);
|
|
|
|
httpHeaders.remove(SpdyHttpHeaders.Names.STREAM_ID);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2013-06-04 23:32:11 +02:00
|
|
|
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
|
2012-05-31 09:37:27 +02:00
|
|
|
// headers are not valid and MUST not be sent.
|
2014-10-31 08:48:28 +01:00
|
|
|
httpHeaders.remove(HttpHeaderNames.CONNECTION);
|
2014-06-14 10:33:34 +02:00
|
|
|
httpHeaders.remove("Keep-Alive");
|
|
|
|
httpHeaders.remove("Proxy-Connection");
|
2014-10-31 08:48:28 +01:00
|
|
|
httpHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING);
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
SpdyHeadersFrame spdyHeadersFrame;
|
|
|
|
if (SpdyCodecUtil.isServerId(streamId)) {
|
2015-09-04 23:17:29 +02:00
|
|
|
spdyHeadersFrame = new DefaultSpdyHeadersFrame(streamId, validateHeaders);
|
2015-01-10 19:53:54 +01:00
|
|
|
} else {
|
2015-09-04 23:17:29 +02:00
|
|
|
spdyHeadersFrame = new DefaultSpdySynReplyFrame(streamId, validateHeaders);
|
2015-01-10 19:53:54 +01:00
|
|
|
}
|
|
|
|
SpdyHeaders frameHeaders = spdyHeadersFrame.headers();
|
2012-05-31 09:37:27 +02:00
|
|
|
// Unfold the first line of the response into name/value pairs
|
2015-01-11 04:45:49 +01:00
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.STATUS, httpResponse.status().codeAsText());
|
|
|
|
frameHeaders.set(SpdyHeaders.HttpNames.VERSION, httpResponse.protocolVersion().text());
|
2012-05-31 09:37:27 +02:00
|
|
|
|
|
|
|
// Transfer the remaining HTTP headers
|
2015-09-04 19:08:03 +02:00
|
|
|
Iterator<Entry<CharSequence, CharSequence>> itr = httpHeaders.iteratorCharSequence();
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
Map.Entry<CharSequence, CharSequence> entry = itr.next();
|
2015-09-04 23:17:29 +02:00
|
|
|
final CharSequence headerName =
|
|
|
|
headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
|
|
|
|
spdyHeadersFrame.headers().add(headerName, entry.getValue());
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
currentStreamId = streamId;
|
|
|
|
spdyHeadersFrame.setLast(isLast(httpResponse));
|
2012-05-31 09:37:27 +02:00
|
|
|
|
2015-01-10 19:53:54 +01:00
|
|
|
return spdyHeadersFrame;
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|
2013-07-19 22:03:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given HTTP message should be considered as a last SPDY frame.
|
|
|
|
*
|
|
|
|
* @param httpMessage check this HTTP message
|
|
|
|
* @return whether the given HTTP message should generate a <em>last</em> SPDY frame.
|
|
|
|
*/
|
|
|
|
private static boolean isLast(HttpMessage httpMessage) {
|
|
|
|
if (httpMessage instanceof FullHttpMessage) {
|
|
|
|
FullHttpMessage fullMessage = (FullHttpMessage) httpMessage;
|
|
|
|
if (fullMessage.trailingHeaders().isEmpty() && !fullMessage.content().isReadable()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-31 09:37:27 +02:00
|
|
|
}
|