protected void onPreface() { notifyPreface(); }
return; if (notifyPreface) onPreface(); state = State.SETTINGS; break; if (!parseHeader(buffer)) return; if (getFrameType() != FrameType.SETTINGS.getType() || hasFlag(Flags.ACK)) notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "invalid_preface"); return; if (!parseBody(buffer)) return; state = State.FRAMES; notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "parser_error");
public boolean upgrade(Request request) { if (HttpMethod.PRI.is(request.getMethod())) { getParser().directUpgrade(); } else { HttpField settingsField = request.getFields().getField(HttpHeader.HTTP2_SETTINGS); if (settingsField == null) throw new BadMessageException("Missing " + HttpHeader.HTTP2_SETTINGS + " header"); String value = settingsField.getValue(); final byte[] settings = B64Code.decodeRFC4648URL(value == null ? "" : value); if (LOG.isDebugEnabled()) LOG.debug("{} settings {}",this,TypeUtil.toHexString(settings)); SettingsFrame settingsFrame = SettingsBodyParser.parseBody(BufferUtil.toBuffer(settings)); if (settingsFrame == null) { LOG.warn("Invalid {} header value: {}", HttpHeader.HTTP2_SETTINGS, value); throw new BadMessageException(); } getParser().standardUpgrade(); upgradeFrames.add(new PrefaceFrame()); upgradeFrames.add(settingsFrame); // Remember the request to send a response from onOpen(). upgradeFrames.add(new HeadersFrame(1, new Request(request), null, true)); } return true; }
@Override public Connection newConnection(Connector connector, EndPoint endPoint) { ServerSessionListener listener = newSessionListener(connector, endPoint); Generator generator = new Generator(connector.getByteBufferPool(), getMaxDynamicTableSize(), getMaxHeaderBlockFragment()); FlowControlStrategy flowControl = getFlowControlStrategyFactory().newFlowControlStrategy(); HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener, flowControl); session.setMaxLocalStreams(getMaxConcurrentStreams()); session.setMaxRemoteStreams(getMaxConcurrentStreams()); // For a single stream in a connection, there will be a race between // the stream idle timeout and the connection idle timeout. However, // the typical case is that the connection will be busier and the // stream idle timeout will expire earlier than the connection's. long streamIdleTimeout = getStreamIdleTimeout(); if (streamIdleTimeout <= 0) streamIdleTimeout = endPoint.getIdleTimeout(); session.setStreamIdleTimeout(streamIdleTimeout); session.setInitialSessionRecvWindow(getInitialSessionRecvWindow()); session.setWriteThreshold(getHttpConfiguration().getOutputBufferSize()); ServerParser parser = newServerParser(connector, session); parser.setMaxFrameLength(getMaxFrameLength()); parser.setMaxSettingsKeys(getMaxSettingsKeys()); HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, httpConfiguration, parser, session, getInputBufferSize(), listener); connection.addListener(sessionContainer); return configure(connection, connector, endPoint); }
protected ServerParser newServerParser(Connector connector, ServerParser.Listener listener) { return new ServerParser(connector.getByteBufferPool(), listener, getMaxDynamicTableSize(), getHttpConfiguration().getRequestHeaderSize()); }
return; if (notifyPreface) onPreface(); state = State.SETTINGS; break; if (!parseHeader(buffer)) return; if (getFrameType() != FrameType.SETTINGS.getType() || hasFlag(Flags.ACK)) notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "invalid_preface"); return; if (!parseBody(buffer)) return; state = State.FRAMES; notifyConnectionFailure(ErrorCode.PROTOCOL_ERROR.code, "parser_error");
protected void onPreface() { notifyPreface(); }