Package io.netty.handler.codec

Examples of io.netty.handler.codec.AsciiString


        EmbeddedChannel decompressor = stream.decompressor();
        if (decompressor == null) {
            if (!endOfStream) {
                // Determine the content encoding.
                AsciiString contentEncoding = headers.get(HttpHeaderNames.CONTENT_ENCODING);
                if (contentEncoding == null) {
                    contentEncoding = HttpHeaderValues.IDENTITY;
                }
                decompressor = newContentDecompressor(contentEncoding);
                if (decompressor != null) {
                    stream.decompressor(decompressor);
                    // Decode the content and remove or replace the existing headers
                    // so that the message looks like a decoded message.
                    AsciiString targetContentEncoding = getTargetContentEncoding(contentEncoding);
                    if (HttpHeaderValues.IDENTITY.equalsIgnoreCase(targetContentEncoding)) {
                        headers.remove(HttpHeaderNames.CONTENT_ENCODING);
                    } else {
                        headers.set(HttpHeaderNames.CONTENT_ENCODING, targetContentEncoding);
                    }
View Full Code Here


    /**
     * Converts a {@link String} into an {@link AsciiString}.
     */
    public static AsciiString as(String value) {
        return new AsciiString(value);
    }
View Full Code Here

    /**
     * Converts a byte array into an {@link AsciiString}.
     */
    public static AsciiString as(byte[] value) {
        return new AsciiString(value);
    }
View Full Code Here

                tableSizeChangeOutput.reset();
            }

            // Write pseudo headers first as required by the HTTP/2 spec.
            for (Http2Headers.PseudoHeaderName pseudoHeader : Http2Headers.PseudoHeaderName.values()) {
                AsciiString name = pseudoHeader.value();
                AsciiString value = headers.get(name);
                if (value != null) {
                    encodeHeader(name, value, stream);
                }
            }

            headers.forEachEntry(new EntryVisitor() {
                @Override
                public boolean visit(Entry<AsciiString, AsciiString> entry) throws Exception {
                    final AsciiString name = entry.getKey();
                    final AsciiString value = entry.getValue();
                    if (!Http2Headers.PseudoHeaderName.isPseudoHeader(name)) {
                        encodeHeader(name, value, stream);
                    }
                    return true;
                }
View Full Code Here

        try {
            final Http2Headers headers = new DefaultHttp2Headers();
            HeaderListener listener = new HeaderListener() {
                @Override
                public void addHeader(byte[] key, byte[] value, boolean sensitive) {
                    headers.add(new AsciiString(key, false), new AsciiString(value, false));
                }
            };

            decoder.decode(in, listener);
            boolean truncated = decoder.endHeaderBlock();
View Full Code Here

        this.password = password;

        ByteBuf authz = Unpooled.copiedBuffer(username + ':' + password, CharsetUtil.UTF_8);
        ByteBuf authzBase64 = Base64.encode(authz, false);

        authorization = new AsciiString(authzBase64.toString(CharsetUtil.US_ASCII));

        authz.release();
        authzBase64.release();
    }
View Full Code Here

    public static Http2Headers toHttp2Headers(FullHttpMessage in) {
        final Http2Headers out = new DefaultHttp2Headers();
        HttpHeaders inHeaders = in.headers();
        if (in instanceof HttpRequest) {
            HttpRequest request = (HttpRequest) in;
            out.path(new AsciiString(request.uri()));
            out.method(new AsciiString(request.method().toString()));

            String value = inHeaders.getAndConvert(HttpHeaderNames.HOST);
            if (value != null) {
                URI hostUri = URI.create(value);
                // The authority MUST NOT include the deprecated "userinfo" subcomponent
                value = hostUri.getAuthority();
                if (value != null) {
                    out.authority(new AsciiString(value.replaceFirst("^.*@", "")));
                }
                value = hostUri.getScheme();
                if (value != null) {
                    out.scheme(new AsciiString(value));
                }
            }

            // Consume the Authority extension header if present
            CharSequence cValue = inHeaders.get(ExtensionHeaderNames.AUTHORITY.text());
            if (cValue != null) {
                out.authority(AsciiString.of(cValue));
            }

            // Consume the Scheme extension header if present
            cValue = inHeaders.get(ExtensionHeaderNames.SCHEME.text());
            if (cValue != null) {
                out.scheme(AsciiString.of(cValue));
            }
        } else if (in instanceof HttpResponse) {
            HttpResponse response = (HttpResponse) in;
            out.status(new AsciiString(Integer.toString(response.status().code())));
        }

        // Add the HTTP headers which have not been consumed above
        try {
            inHeaders.forEachEntry(new EntryVisitor() {
                @Override
                public boolean visit(Entry<CharSequence, CharSequence> entry) throws Exception {
                    final AsciiString aName = AsciiString.of(entry.getKey()).toLowerCase();
                    if (!HTTP_TO_HTTP2_HEADER_BLACKLIST.contains(aName)) {
                        AsciiString aValue = AsciiString.of(entry.getValue());
                        out.add(aName, aValue);
                    }
                    return true;
                }
            });
View Full Code Here

            translations = request ? REQUEST_HEADER_TRANSLATIONS : RESPONSE_HEADER_TRANSLATIONS;
        }

        @Override
        public boolean visit(Entry<AsciiString, AsciiString> entry) throws Http2Exception {
            final AsciiString name = entry.getKey();
            final AsciiString value = entry.getValue();
            AsciiString translatedName = translations.get(name);
            if (translatedName != null || !Http2Headers.PseudoHeaderName.isPseudoHeader(name)) {
                if (translatedName == null) {
                    translatedName = name;
                }

                // http://tools.ietf.org/html/draft-ietf-httpbis-http2-14#section-8.1.2.3
                // All headers that start with ':' are only valid in HTTP/2 context
                if (translatedName.isEmpty() || translatedName.charAt(0) == ':') {
                    throw Http2Exception
                                    .protocolError("Unknown HTTP/2 header '%s' encountered in translation to HTTP/1.x",
                                                    translatedName);
                } else {
                    output.add(translatedName, value);
View Full Code Here

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) {
            // Write an HTTP/2 response to the upgrade request
            Http2Headers headers =
                    new DefaultHttp2Headers().status(new AsciiString("200"))
                    .set(new AsciiString(UPGRADE_RESPONSE_HEADER), new AsciiString("true"));
            encoder().writeHeaders(ctx, 1, headers, 0, true, ctx.newPromise());
        }
        super.userEventTriggered(ctx, evt);
    }
View Full Code Here

        /**
         * Sends a "Hello World" DATA frame to the client.
         */
        private void sendResponse(ChannelHandlerContext ctx, int streamId, ByteBuf payload) {
            // Send a frame for the response status
            Http2Headers headers = new DefaultHttp2Headers().status(new AsciiString("200"));
            encoder.writeHeaders(ctx, streamId, headers, 0, false, ctx.newPromise());
            encoder.writeData(ctx, streamId, payload, 0, true, ctx.newPromise());
            ctx.flush();
        }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.AsciiString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.