Example usage for io.netty.handler.codec.http2 Http2Headers authority

List of usage examples for io.netty.handler.codec.http2 Http2Headers authority

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2Headers authority.

Prototype

Http2Headers authority(CharSequence value);

Source Link

Document

Sets the PseudoHeaderName#AUTHORITY header or null if there is no such header

Usage

From source file:example.http2.helloworld.server.HelloWorldHttp2Handler.java

License:Apache License

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);
    }/*from w ww .j a v  a2 s  . c om*/
    return http2Headers;
}

From source file:io.vertx.core.http.impl.Http2ServerConnection.java

License:Open Source License

synchronized void sendPush(int streamId, String host, HttpMethod method, MultiMap headers, String path,
        Handler<AsyncResult<HttpServerResponse>> completionHandler) {
    Http2Headers headers_ = new DefaultHttp2Headers();
    if (method == HttpMethod.OTHER) {
        throw new IllegalArgumentException("Cannot push HttpMethod.OTHER");
    } else {/*from w ww  . j a va  2  s  .  co m*/
        headers_.method(method.name());
    }
    headers_.path(path);
    headers_.scheme(isSsl() ? "https" : "http");
    if (host != null) {
        headers_.authority(host);
    }
    if (headers != null) {
        headers.forEach(header -> headers_.add(header.getKey(), header.getValue()));
    }
    handler.writePushPromise(streamId, headers_, new Handler<AsyncResult<Integer>>() {
        @Override
        public void handle(AsyncResult<Integer> ar) {
            if (ar.succeeded()) {
                synchronized (Http2ServerConnection.this) {
                    int promisedStreamId = ar.result();
                    String contentEncoding = HttpUtils.determineContentEncoding(headers_);
                    Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
                    boolean writable = handler.encoder().flowController().isWritable(promisedStream);
                    Push push = new Push(promisedStream, contentEncoding, method, path, writable,
                            completionHandler);
                    streams.put(promisedStreamId, push);
                    if (maxConcurrentStreams == null || concurrentStreams < maxConcurrentStreams) {
                        concurrentStreams++;
                        context.executeFromIO(push::complete);
                    } else {
                        pendingPushes.add(push);
                    }
                }
            } else {
                context.executeFromIO(() -> {
                    completionHandler.handle(Future.failedFuture(ar.cause()));
                });
            }
        }
    });
}

From source file:org.jboss.aerogear.webpush.WebPushClient.java

License:Apache License

private Http2Headers http2Headers(final HttpMethod method, final String url) {
    final URI hostUri = URI.create("https://" + host + ":" + port + "/" + url);
    final Http2Headers headers = new DefaultHttp2Headers().method(AsciiString.of(method.name()));
    headers.path(asciiString(url));/*from w ww.  j  a v a  2  s.c  om*/
    headers.authority(asciiString(hostUri.getAuthority()));
    headers.scheme(asciiString(hostUri.getScheme()));
    return headers;
}

From source file:org.wso2.carbon.transport.http.netty.listener.http2.HTTP2ResponseCallback.java

License:Open Source License

/**
 * Create HTTP/2 Headers for response/*w  w  w .j  a v  a2  s. c o m*/
 *
 * @param msg Carbon Message
 * @return HTTP/2 Headers
 */
private Http2Headers createHttp2Headers(CarbonMessage msg) {
    Http2Headers http2Headers = new DefaultHttp2Headers()
            .status(String.valueOf(Util.getIntValue(msg, Constants.HTTP_STATUS_CODE, 200)))
            .method(Util.getStringValue(msg, Constants.HTTP_METHOD, DEFAULT_HTTP_METHOD_POST))
            .path(msg.getProperty(Constants.TO) != null ? msg.getProperty(Constants.TO).toString() : "/")
            .scheme(msg.getProperty(Constants.SCHEME) != null ? msg.getProperty(Constants.SCHEME).toString()
                    : Constants.PROTOCOL_NAME);
    //set Authority Header
    if (msg.getProperty(Constants.AUTHORITY) != null) {
        http2Headers.authority(Constants.AUTHORITY);
    } else {
        http2Headers.authority(((InetSocketAddress) ctx.channel().remoteAddress()).getHostName());
    }

    msg.getHeaders().getAll().forEach(k -> http2Headers.add(k.getName().toLowerCase(), k.getValue()));
    return http2Headers;
}