use of com.predic8.membrane.core.transport.http2.frame.HeadersFrame in project service-proxy by membrane.
the class Http2Logic method handleFrame.
private void handleFrame(HeadersFrame headers) throws IOException {
int streamId1 = headers.getFrame().getStreamId();
if (streamId1 == 0)
throw new FatalConnectionException(ERROR_PROTOCOL_ERROR);
StreamInfo streamInfo = streams.get(streamId1);
if (streamInfo == null) {
streamInfo = new StreamInfo(streamId1, sender, peerSettings, ourSettings);
streams.put(streamId1, streamInfo);
}
streamInfo.receivedHeaders();
if (headers.isPriority())
priorityTree.reprioritize(streamInfo, headers.getWeight(), streams.get(headers.getStreamDependency()), headers.isExclusive());
else
priorityTree.reprioritize(streamInfo, 16, null, false);
List<HeaderBlockFragment> headerFrames = new ArrayList<>();
headerFrames.add(headers);
HeaderBlockFragment last = headers;
while (!last.isEndHeaders()) {
Frame frame = new Frame(ourSettings);
frame.read(srcIn);
if (frame.getType() != TYPE_CONTINUATION)
throw new FatalConnectionException(ERROR_PROTOCOL_ERROR);
last = frame.asContinuation();
int streamId = frame.getStreamId();
if (streamId != streamId1)
throw new FatalConnectionException(ERROR_PROTOCOL_ERROR);
headerFrames.add(last);
}
Message request = messageHandler.createMessage();
StringBuilder sb = log.isDebugEnabled() ? new StringBuilder() : null;
if (sb != null) {
sb.append("Headers on stream ");
sb.append(streamId1);
sb.append(":\n");
}
decoder.decode(getPackedHeaderStream(headerFrames), new HeaderListener() {
@Override
public void addHeader(byte[] name, byte[] value, boolean sensitive) {
String key = new String(name);
String val = new String(value);
if (sb != null) {
sb.append(key);
sb.append(": ");
sb.append(val);
sb.append("\n");
}
if (":method".equals(key) && request instanceof Request)
((Request) request).setMethod(val);
else if (":scheme".equals(key))
// ignore
;
else if (":authority".equals(key))
request.getHeader().setHost(val);
else if (":path".equals(key) && request instanceof Request) {
((Request) request).setUri(val);
log.info("streamId=" + streamId1 + " uri=" + val);
} else if (":status".equals(key) && request instanceof Response) {
((Response) request).setStatusCode(Integer.parseInt(val));
log.debug("streamId=" + streamId1 + " status=" + val);
} else
request.getHeader().add(key, val);
}
});
decoder.endHeaderBlock();
if (sb != null)
log.debug(sb.toString());
if (!headers.isEndStream())
request.setBody(streamInfo.createBody());
messageHandler.handleExchange(streamInfo, request, showSSLExceptions, remoteAddr);
if (headers.isEndStream())
streamInfo.receivedEndStream(false);
}
Aggregations