@Override public String scheme() { CharSequence scheme = headers.scheme(); return scheme != null ? scheme.toString() : null; }
private static void setHttp2Scheme(HttpHeaders in, URI uri, Http2Headers out) { String value = uri.getScheme(); if (value != null) { out.scheme(new AsciiString(value)); return; } // Consume the Scheme extension header if present CharSequence cValue = in.get(ExtensionHeaderNames.SCHEME.text()); if (cValue != null) { out.scheme(AsciiString.of(cValue)); return; } if (uri.getPort() == HTTPS.port()) { out.scheme(HTTPS.name()); } else if (uri.getPort() == HTTP.port()) { out.scheme(HTTP.name()); } else { throw new IllegalArgumentException(":scheme must be specified. " + "see https://tools.ietf.org/html/rfc7540#section-8.1.2.3"); } }
private static boolean isMalformedRequest(Http2Headers headers) { if (headers.method() == null) { return true; } String method = headers.method().toString(); if (method.equals("CONNECT")) { if (headers.scheme() != null || headers.path() != null || headers.authority() == null) { return true; } } else { if (headers.method() == null || headers.scheme() == null || headers.path() == null) { return true; } } if (headers.authority() != null) { URI uri; try { uri = new URI(null, headers.authority().toString(), null, null, null); } catch (URISyntaxException e) { return true; } if (uri.getRawUserInfo() != null) { return true; } } return false; }
headers_.scheme(isSsl() ? "https" : "http"); if (host != null) { headers_.authority(host);
private static Http2Headers http1HeadersToHttp2Headers(FullHttpRequest request) { CharSequence host = request.headers().get(HttpHeaderNames.HOST); Http2Headers http2Headers = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()) .path(request.uri()) .scheme(HttpScheme.HTTP.name()); if (host != null) { http2Headers.authority(host); } return http2Headers; }
private static Http2Headers http1HeadersToHttp2Headers(FullHttpRequest request) { CharSequence host = request.headers().get(HttpHeaderNames.HOST); Http2Headers http2Headers = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()) .path(request.uri()) .scheme(HttpScheme.HTTP.name()); if (host != null) { http2Headers.authority(host); } return http2Headers; }
@Override public void push(final String method, final String path, final Map<String, Object> headers) { ctx.channel().eventLoop().execute(() -> { AsciiString streamIdHeader = HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(); Http2Connection connection = encoder.connection(); int nextStreamId = connection.local().incrementAndGetNextStreamId(); Http2Headers h2headers = new DefaultHttp2Headers() .path(path) .method(method) .authority(authority) .scheme(scheme); headers.forEach((n, v) -> h2headers.add(n, v.toString())); encoder.writePushPromise(ctx, streamId, nextStreamId, h2headers, 0, ctx.newPromise()); // TODO: Is there another way of handling a push promise? DefaultFullHttpRequest pushRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method.toUpperCase()), path, Unpooled.EMPTY_BUFFER, new DefaultHttpHeaders(false).set(streamIdHeader, nextStreamId), EmptyHttpHeaders.INSTANCE); ctx.pipeline().fireChannelRead(pushRequest); ctx.pipeline().fireChannelReadComplete(); }); }
} else { h.path(uri); h.scheme(conn.isSSL() ? "https" : "http"); if (hostHeader != null) { h.authority(hostHeader);
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) { HttpServerUpgradeHandler.UpgradeEvent upgradeEvent = (HttpServerUpgradeHandler.UpgradeEvent) evt; // Map initial request headers to HTTP2 FullHttpRequest request = upgradeEvent.upgradeRequest(); Http2Headers headers = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()) .path(request.uri()) .scheme(HttpScheme.HTTP.name()); CharSequence host = request.headers().get(HttpHeaderNames.HOST); if (host != null) { headers.authority(host); } // Process mapped headers onHeadersRead(ctx, 1, headers, 0, true); } super.userEventTriggered(ctx, evt); }
@Override public String scheme() { CharSequence scheme = headers.scheme(); return scheme != null ? scheme.toString() : null; }
protected Http2Headers getHeadersForPushNotification(final ApnsPushNotification pushNotification, final int streamId) { final Http2Headers headers = new DefaultHttp2Headers() .method(HttpMethod.POST.asciiName()) .authority(this.authority) .path(APNS_PATH_PREFIX + pushNotification.getToken()) .scheme(HttpScheme.HTTPS.name()) .addInt(APNS_EXPIRATION_HEADER, pushNotification.getExpiration() == null ? 0 : (int) (pushNotification.getExpiration().getTime() / 1000)); if (pushNotification.getCollapseId() != null) { headers.add(APNS_COLLAPSE_ID_HEADER, pushNotification.getCollapseId()); } if (pushNotification.getPriority() != null) { headers.addInt(APNS_PRIORITY_HEADER, pushNotification.getPriority().getCode()); } if (pushNotification.getTopic() != null) { headers.add(APNS_TOPIC_HEADER, pushNotification.getTopic()); } if (pushNotification.getApnsId() != null) { headers.add(APNS_ID_HEADER, FastUUID.toString(pushNotification.getApnsId())); } return headers; }
private static boolean isMalformedRequest(Http2Headers headers) { if (headers.method() == null) { return true; } String method = headers.method().toString(); if (method.equals("CONNECT")) { if (headers.scheme() != null || headers.path() != null || headers.authority() == null) { return true; } } else { if (headers.method() == null || headers.scheme() == null || headers.path() == null) { return true; } } if (headers.authority() != null) { URI uri; try { uri = new URI(null, headers.authority().toString(), null, null, null); } catch (URISyntaxException e) { return true; } if (uri.getRawUserInfo() != null) { return true; } } return false; }
headers_.scheme(isSsl() ? "https" : "http"); if (host != null) { headers_.authority(host);
} else { h.path(uri); h.scheme(conn.isSSL() ? "https" : "http"); if (hostHeader != null) { h.authority(hostHeader);
private static void setHttp2Scheme(HttpHeaders in, URI uri, Http2Headers out) { String value = uri.getScheme(); if (value != null) { out.scheme(new AsciiString(value)); return; } // Consume the Scheme extension header if present CharSequence cValue = in.get(ExtensionHeaderNames.SCHEME.text()); if (cValue != null) { out.scheme(AsciiString.of(cValue)); return; } if (uri.getPort() == HTTPS.port()) { out.scheme(HTTPS.name()); } else if (uri.getPort() == HTTP.port()) { out.scheme(HTTP.name()); } else { throw new IllegalArgumentException(":scheme must be specified. " + "see https://tools.ietf.org/html/rfc7540#section-8.1.2.3"); } }
private static void setHttp2Scheme(HttpHeaders in, URI uri, Http2Headers out) { String value = uri.getScheme(); if (value != null) { out.scheme(new AsciiString(value)); return; } // Consume the Scheme extension header if present CharSequence cValue = in.get(ExtensionHeaderNames.SCHEME.text()); if (cValue != null) { out.scheme(AsciiString.of(cValue)); return; } if (uri.getPort() == HTTPS.port()) { out.scheme(HTTPS.name()); } else if (uri.getPort() == HTTP.port()) { out.scheme(HTTP.name()); } else { throw new IllegalArgumentException(":scheme must be specified. " + "see https://tools.ietf.org/html/rfc7540#section-8.1.2.3"); } }
private static Http2Headers http1HeadersToHttp2Headers(FullHttpRequest request) { CharSequence host = request.headers().get(HttpHeaderNames.HOST); Http2Headers http2Headers = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()) .path(request.uri()) .scheme(HttpScheme.HTTP.name()); if (host != null) { http2Headers.authority(host); } return http2Headers; }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) { HttpServerUpgradeHandler.UpgradeEvent upgradeEvent = (HttpServerUpgradeHandler.UpgradeEvent) evt; // Map initial request headers to HTTP2 FullHttpRequest request = upgradeEvent.upgradeRequest(); Http2Headers headers = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()) .path(request.uri()) .scheme(HttpScheme.HTTP.name()); CharSequence host = request.headers().get(HttpHeaderNames.HOST); if (host != null) { headers.authority(host); } // Process mapped headers onHeadersRead(ctx, 1, headers, 0, true); } super.userEventTriggered(ctx, evt); }
public void writeResponse(Http2Response response) { Http2Headers headers = response.getHeaders(); headers.add(BaseHttpEntity.REQUEST_ID, sourceRequest.getRequestId()); headers.add(RESPONSE_STATUS, headers.status()); headers.add(DATA_STREAM_ID, getStreamId()); headers.path(sourceRequest.getHeaders().path()); headers.method("POST"); headers.scheme("https"); headers.remove(PseudoHeaderName.STATUS.value()); byte[] data = response.getContent(); CompletableFuture<StreamWriteOperation> future; boolean endOfStream = (data == null || data.length == 0); future = connection.writeHeaders(headers, endOfStream, null); if (!endOfStream) { future.thenAccept(writeOperation -> writeOperation.writeData(response.getContent(), true)); } future.thenAccept(StreamWriteOperation::closeStream); }
protected Http2Headers getHeadersForPushNotification(final ApnsPushNotification pushNotification, final int streamId) { final Http2Headers headers = new DefaultHttp2Headers() .method(HttpMethod.POST.asciiName()) .authority(this.authority) .path(APNS_PATH_PREFIX + pushNotification.getToken()) .scheme(HttpScheme.HTTPS.name()) .addInt(APNS_EXPIRATION_HEADER, pushNotification.getExpiration() == null ? 0 : (int) (pushNotification.getExpiration().getTime() / 1000)); if (pushNotification.getCollapseId() != null) { headers.add(APNS_COLLAPSE_ID_HEADER, pushNotification.getCollapseId()); } if (pushNotification.getPriority() != null) { headers.addInt(APNS_PRIORITY_HEADER, pushNotification.getPriority().getCode()); } if (pushNotification.getTopic() != null) { headers.add(APNS_TOPIC_HEADER, pushNotification.getTopic()); } if (pushNotification.getApnsId() != null) { headers.add(APNS_ID_HEADER, FastUUID.toString(pushNotification.getApnsId())); } return headers; }