in src/main/java/com/twitter/http2/HttpStreamEncoder.java [281:312]
private HttpHeadersFrame createHttpHeadersFrame(HttpRequest httpRequest)
throws Exception {
// Get the Stream-ID from the headers
int streamId = HttpHeaders.getIntHeader(httpRequest, "X-SPDY-Stream-ID");
httpRequest.headers().remove("X-SPDY-Stream-ID");
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpRequest.headers().remove(HttpHeaders.Names.CONNECTION);
httpRequest.headers().remove("Keep-Alive");
httpRequest.headers().remove("Proxy-Connection");
httpRequest.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
HttpHeadersFrame httpHeadersFrame = new DefaultHttpHeadersFrame(streamId);
// Unfold the first line of the request into name/value pairs
httpHeadersFrame.headers().add(":method", httpRequest.getMethod().name());
httpHeadersFrame.headers().set(":scheme", "https");
httpHeadersFrame.headers().add(":path", httpRequest.getUri());
// Replace the HTTP host header with the SPDY host header
String host = httpRequest.headers().get(HttpHeaders.Names.HOST);
httpRequest.headers().remove(HttpHeaders.Names.HOST);
httpHeadersFrame.headers().add(":authority", host);
// Transfer the remaining HTTP headers
for (Map.Entry<String, String> entry : httpRequest.headers()) {
httpHeadersFrame.headers().add(entry.getKey(), entry.getValue());
}
return httpHeadersFrame;
}