Java Code Examples for org.apache.http.HttpRequest#removeHeaders()

The following examples show how to use org.apache.http.HttpRequest#removeHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: B2ErrorResponseInterceptor.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process(final HttpRequest request, final HttpContext context) {
    if(StringUtils.contains(request.getRequestLine().getUri(), "b2_authorize_account")) {
        // Skip setting token for
        if(log.isDebugEnabled()) {
            log.debug("Skip setting token in b2_authorize_account");
        }
        return;
    }
    switch(request.getRequestLine().getMethod()) {
        case "POST":
            // Do not override Authorization header for upload requests with upload URL token
            if(StringUtils.contains(request.getRequestLine().getUri(), "b2_upload_part")
                || StringUtils.contains(request.getRequestLine().getUri(), "b2_upload_file")) {
                break;
            }
        default:
            if(StringUtils.isNotBlank(authorizationToken)) {
                request.removeHeaders(HttpHeaders.AUTHORIZATION);
                request.addHeader(HttpHeaders.AUTHORIZATION, authorizationToken);
            }
    }
}
 
Example 2
Source File: OAuth2RequestInterceptor.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    if(tokens.isExpired()) {
        try {
            tokens = this.refresh(tokens);
        }
        catch(BackgroundException e) {
            log.warn(String.format("Failure refreshing OAuth 2 tokens %s. %s", tokens, e));
            // Follow up error 401 handled in error interceptor
        }
    }
    if(StringUtils.isNotBlank(tokens.getAccessToken())) {
        if(log.isInfoEnabled()) {
            log.info(String.format("Authorizing service request with OAuth2 access token %s", tokens.getAccessToken()));
        }
        request.removeHeaders(HttpHeaders.AUTHORIZATION);
        request.addHeader(new BasicHeader(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", tokens.getAccessToken())));
    }
}
 
Example 3
Source File: ApacheHttpClientAdapter.java    From uavstack with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {

    if (args.length < 2) {
        return;
    }

    /**
     * after precap the client's span is created, set the span meta into http request header
     */
    String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);

    Span span = this.spanFactory.getSpanFromContext(url);

    String spanMeta = this.spanFactory.getSpanMeta(span);

    HttpRequest request = (HttpRequest) args[1];

    request.removeHeaders(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
    request.addHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);

    handleSlowOperSupporter(request, span, context);
}
 
Example 4
Source File: RequestProtocolCompliance.java    From apigee-android-sdk with Apache License 2.0 6 votes vote down vote up
private void decrementOPTIONSMaxForwardsIfGreaterThen0(HttpRequest request) {
	if (!HeaderConstants.OPTIONS_METHOD.equals(request.getRequestLine()
			.getMethod())) {
		return;
	}

	Header maxForwards = request
			.getFirstHeader(HeaderConstants.MAX_FORWARDS);
	if (maxForwards == null) {
		return;
	}

	request.removeHeaders(HeaderConstants.MAX_FORWARDS);
	int currentMaxForwards = Integer.parseInt(maxForwards.getValue());

	request.setHeader(HeaderConstants.MAX_FORWARDS,
			Integer.toString(currentMaxForwards - 1));
}
 
Example 5
Source File: SDSErrorResponseInterceptor.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void process(final HttpRequest request, final HttpContext context) {
    if(StringUtils.isNotBlank(token)) {
        request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER);
        request.addHeader(SDSSession.SDS_AUTH_TOKEN_HEADER, token);
    }
}