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

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

Introduction

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

Prototype

Http2Headers scheme(CharSequence value);

Source Link

Document

Sets the PseudoHeaderName#SCHEME header if there is no such header

Usage

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 {//w  w  w .java  2 s  .c o 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));// www. ja  v  a 2 s  . c o  m
    headers.authority(asciiString(hostUri.getAuthority()));
    headers.scheme(asciiString(hostUri.getScheme()));
    return headers;
}