Example usage for io.netty.handler.codec.http HttpHeaders remove

List of usage examples for io.netty.handler.codec.http HttpHeaders remove

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaders remove.

Prototype

public HttpHeaders remove(CharSequence name) 

Source Link

Document

Removes the header with the specified name.

Usage

From source file:cc.changic.platform.etl.schedule.http.HttpHeaderUtil.java

License:Apache License

/**
 * Sets the value of the {@code "Connection"} header depending on the
 * protocol version of the specified message.  This getMethod sets or removes
 * the {@code "Connection"} header depending on what the default keep alive
 * mode of the message's protocol version is, as specified by
 * {@link io.netty.handler.codec.http.HttpVersion#isKeepAliveDefault()}.
 * <ul>/*  w w w. j  av  a  2s .  c o m*/
 * <li>If the connection is kept alive by default:
 *     <ul>
 *     <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * <li>If the connection is closed by default:
 *     <ul>
 *     <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * </ul>
 */
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
    HttpHeaders h = message.headers();
    if (message.protocolVersion().isKeepAliveDefault()) {
        if (keepAlive) {
            h.remove(Names.CONNECTION);
        } else {
            h.set(Names.CONNECTION, Values.CLOSE);
        }
    } else {
        if (keepAlive) {
            h.set(Names.CONNECTION, Values.KEEP_ALIVE);
        } else {
            h.remove(Names.CONNECTION);
        }
    }
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpClientRequestHandler.java

License:Open Source License

private String getAndRemove(HttpHeaders headers, String headerName) {
    String headerValue = headers.get(headerName);
    headers.remove(headerName);
    return headerValue;
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpServerResponseHandler.java

License:Open Source License

private void parseResponseHeaders(Operation request, HttpResponse nettyResponse) {
    HttpHeaders headers = nettyResponse.headers();
    if (headers.isEmpty()) {
        return;/*from w w w.  j  ava2s  .co  m*/
    }

    request.setKeepAlive(HttpUtil.isKeepAlive(nettyResponse));
    if (HttpUtil.isContentLengthSet(nettyResponse)) {
        request.setContentLength(HttpUtil.getContentLength(nettyResponse));
        headers.remove(HttpHeaderNames.CONTENT_LENGTH);
    }

    String contentType = headers.get(HttpHeaderNames.CONTENT_TYPE);
    headers.remove(HttpHeaderNames.CONTENT_TYPE);
    if (contentType != null) {
        request.setContentType(contentType);
    }

    for (Entry<String, String> h : headers) {
        String key = h.getKey();
        String value = h.getValue();
        if (Operation.STREAM_ID_HEADER.equals(key)) {
            // Prevent allocation of response headers in Operation and hide the stream ID
            // header, since it is manipulated by the HTTP layer, not services
            continue;
        }
        request.addResponseHeader(key, value);
    }
}

From source file:divconq.http.multipart.HttpPostRequestEncoder.java

License:Apache License

/**
 * Finalize the request by preparing the Header in the request and returns the request ready to be sent.<br>
 * Once finalized, no data must be added.<br>
 * If the request does not need chunk (isChunked() == false), this request is the only object to send to the remote
 * server.//from  w w  w.  ja  va2s.com
 *
 * @return the request object (chunked or not according to size of body)
 * @throws ErrorDataEncoderException
 *             if the encoding is in error or if the finalize were already done
 */
public HttpRequest finalizeRequest() throws ErrorDataEncoderException {
    // Finalize the multipartHttpDatas
    if (!headerFinalized) {
        if (isMultipart) {
            InternalAttribute internal = new InternalAttribute(charset);
            if (duringMixedMode) {
                internal.addValue("\r\n--" + multipartMixedBoundary + "--");
            }
            internal.addValue("\r\n--" + multipartDataBoundary + "--\r\n");
            multipartHttpDatas.add(internal);
            multipartMixedBoundary = null;
            currentFileUpload = null;
            duringMixedMode = false;
            globalBodySize += internal.size();
        }
        headerFinalized = true;
    } else {
        throw new ErrorDataEncoderException("Header already encoded");
    }

    HttpHeaders headers = request.headers();
    List<String> contentTypes = headers.getAll(HttpHeaders.Names.CONTENT_TYPE);
    List<String> transferEncoding = headers.getAll(HttpHeaders.Names.TRANSFER_ENCODING);
    if (contentTypes != null) {
        headers.remove(HttpHeaders.Names.CONTENT_TYPE);
        for (String contentType : contentTypes) {
            // "multipart/form-data; boundary=--89421926422648"
            if (contentType.toLowerCase().startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA.toString())) {
                // ignore
            } else if (contentType.toLowerCase()
                    .startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED.toString())) {
                // ignore
            } else {
                headers.add(HttpHeaders.Names.CONTENT_TYPE, contentType);
            }
        }
    }
    if (isMultipart) {
        String value = HttpHeaders.Values.MULTIPART_FORM_DATA + "; " + HttpHeaders.Values.BOUNDARY + '='
                + multipartDataBoundary;
        headers.add(HttpHeaders.Names.CONTENT_TYPE, value);
    } else {
        // Not multipart
        headers.add(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
    }
    // Now consider size for chunk or not
    long realSize = globalBodySize;
    if (isMultipart) {
        iterator = multipartHttpDatas.listIterator();
    } else {
        realSize -= 1; // last '&' removed
        iterator = multipartHttpDatas.listIterator();
    }
    headers.set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(realSize));
    if (realSize > HttpPostBodyUtil.chunkSize || isMultipart) {
        isChunked = true;
        if (transferEncoding != null) {
            headers.remove(HttpHeaders.Names.TRANSFER_ENCODING);
            for (String v : transferEncoding) {
                if (HttpHeaders.equalsIgnoreCase(v, HttpHeaders.Values.CHUNKED)) {
                    // ignore
                } else {
                    headers.add(HttpHeaders.Names.TRANSFER_ENCODING, v);
                }
            }
        }
        HttpHeaders.setTransferEncodingChunked(request);

        // wrap to hide the possible content
        return new WrappedHttpRequest(request);
    } else {
        // get the only one body and set it to the request
        HttpContent chunk = nextChunk();
        if (request instanceof FullHttpRequest) {
            FullHttpRequest fullRequest = (FullHttpRequest) request;
            ByteBuf chunkContent = chunk.content();
            if (fullRequest.content() != chunkContent) {
                fullRequest.content().clear().writeBytes(chunkContent);
                chunkContent.release();
            }
            return fullRequest;
        } else {
            return new WrappedFullHttpRequest(request, chunk);
        }
    }
}

From source file:io.advantageous.conekt.http.impl.HttpClientRequestImpl.java

License:Open Source License

private void prepareHeaders() {
    HttpHeaders headers = request.headers();
    headers.remove(io.advantageous.conekt.http.HttpHeaders.TRANSFER_ENCODING);
    if (!headers.contains(io.advantageous.conekt.http.HttpHeaders.HOST)) {
        request.headers().set(io.advantageous.conekt.http.HttpHeaders.HOST, conn.hostHeader());
    }//from w  ww  .j  a v a2s. c  om
    if (chunked) {
        HttpHeaders.setTransferEncodingChunked(request);
    }
    if (client.getOptions().isTryUseCompression()
            && request.headers().get(io.advantageous.conekt.http.HttpHeaders.ACCEPT_ENCODING) == null) {
        // if compression should be used but nothing is specified by the user support deflate and gzip.
        request.headers().set(io.advantageous.conekt.http.HttpHeaders.ACCEPT_ENCODING,
                io.advantageous.conekt.http.HttpHeaders.DEFLATE_GZIP);
    }
    if (!client.getOptions().isKeepAlive()
            && client.getOptions().getProtocolVersion() == io.advantageous.conekt.http.HttpVersion.HTTP_1_1) {
        request.headers().set(io.advantageous.conekt.http.HttpHeaders.CONNECTION,
                io.advantageous.conekt.http.HttpHeaders.CLOSE);
    } else if (client.getOptions().isKeepAlive()
            && client.getOptions().getProtocolVersion() == io.advantageous.conekt.http.HttpVersion.HTTP_1_0) {
        request.headers().set(io.advantageous.conekt.http.HttpHeaders.CONNECTION,
                io.advantageous.conekt.http.HttpHeaders.KEEP_ALIVE);
    }
}

From source file:io.jsync.http.impl.DefaultHttpClientRequest.java

License:Open Source License

private void prepareHeaders() {
    HttpHeaders headers = request.headers();
    headers.remove(io.jsync.http.HttpHeaders.TRANSFER_ENCODING);
    if (!raw) {/* www .  ja va2  s  . c o m*/
        if (!headers.contains(io.jsync.http.HttpHeaders.HOST)) {
            request.headers().set(io.jsync.http.HttpHeaders.HOST, conn.hostHeader);
        }
        if (chunked) {
            HttpUtil.setTransferEncodingChunked(request, true);
        }
    }
    if (client.getTryUseCompression()
            && request.headers().get(io.jsync.http.HttpHeaders.ACCEPT_ENCODING) == null) {
        // if compression should be used but nothing is specified by the user support deflate and gzip.
        request.headers().set(io.jsync.http.HttpHeaders.ACCEPT_ENCODING,
                io.jsync.http.HttpHeaders.DEFLATE_GZIP);

    }
}

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

License:Open Source License

private void prepareHeaders(HttpRequest request, String hostHeader, boolean chunked) {
    HttpHeaders headers = request.headers();
    headers.remove(TRANSFER_ENCODING);
    if (!headers.contains(HOST)) {
        request.headers().set(HOST, hostHeader);
    }//from   w w  w .j  a v  a 2s. c  om
    if (chunked) {
        HttpHeaders.setTransferEncodingChunked(request);
    }
    if (client.getOptions().isTryUseCompression() && request.headers().get(ACCEPT_ENCODING) == null) {
        // if compression should be used but nothing is specified by the user support deflate and gzip.
        request.headers().set(ACCEPT_ENCODING, DEFLATE_GZIP);
    }
    if (!client.getOptions().isKeepAlive()
            && client.getOptions().getProtocolVersion() == io.vertx.core.http.HttpVersion.HTTP_1_1) {
        request.headers().set(CONNECTION, CLOSE);
    } else if (client.getOptions().isKeepAlive()
            && client.getOptions().getProtocolVersion() == io.vertx.core.http.HttpVersion.HTTP_1_0) {
        request.headers().set(CONNECTION, KEEP_ALIVE);
    }
}

From source file:org.asynchttpclient.netty.handler.intercept.Redirect30xInterceptor.java

License:Open Source License

private HttpHeaders propagatedHeaders(Request request, Realm realm, boolean keepBody) {

    HttpHeaders headers = request.getHeaders()//
            .remove(HttpHeaders.Names.HOST)//
            .remove(HttpHeaders.Names.CONTENT_LENGTH);

    if (!keepBody) {
        headers.remove(HttpHeaders.Names.CONTENT_TYPE);
    }//from   www .j  av a2 s  . com

    if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
        headers.remove(AUTHORIZATION)//
                .remove(PROXY_AUTHORIZATION);
    }
    return headers;
}

From source file:org.ballerinalang.mime.nativeimpl.headers.RemoveHeader.java

License:Open Source License

@Override
public void execute(Context context) {
    BMap<String, BValue> entityStruct = (BMap<String, BValue>) context.getRefArgument(FIRST_PARAMETER_INDEX);
    String headerName = context.getStringArgument(FIRST_PARAMETER_INDEX);
    if (entityStruct.getNativeData(ENTITY_HEADERS) != null) {
        HttpHeaders httpHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
        httpHeaders.remove(headerName);
    }//from   w ww .  j ava 2s . c o m
    context.setReturnValues();
}

From source file:org.ballerinalang.net.grpc.nativeimpl.headers.Remove.java

License:Open Source License

@Override
public void execute(Context context) {
    BMap<String, BValue> headerValues = (BMap<String, BValue>) context.getRefArgument(0);
    HttpHeaders headers = headerValues != null ? (HttpHeaders) headerValues.getNativeData(MESSAGE_HEADERS)
            : null;/*from  w  w  w.j  a  va  2  s .c om*/
    String headerName = context.getStringArgument(0);
    if (headers != null) {
        headers.remove(headerName);
    }
    context.setReturnValues();
}