hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd W Lainhart <lainh...@us.ibm.com>
Subject Re: HttpContext and RequestConfig
Date Wed, 15 Oct 2014 14:50:24 GMT
Thanks Oleg -

Unless I'm missing something, I was thinking that it had to be something 
along these lines:

            /*
             * Disable redirection for this one POST request
             */
            RequestConfig oldConfig = context.getRequestConfig();
            RequestConfig newConfig = RequestConfig.custom
().setRedirectsEnabled(false).build();
            context.setRequestConfig(newConfig);
 
            try {
                response = httpClient.execute(targetHost, postMethod, 
context);
            } finally {
                context.setRequestConfig(oldConfig);
            }
 



> 
> Well, in the worst case would this do the trick?
> ---
> class MyHttpContext implements HttpContext {
> 
>     private final HttpContext context;
>     private RequestConfig requestConfig;
> 
>     public MyHttpContext(final HttpContext context) {
>         super();
>         this.context = Args.notNull(context, "HTTP context");
>     }
> 
>     public Object getAttribute(final String id) {
>         if (HttpClientContext.REQUEST_CONFIG.equals(id)) {
>             if (this.requestConfig != null) {
>                 return this.requestConfig;
>             } else {
>                 return this.context.getAttribute(id);
>             }
>         } else {
>             return this.context.getAttribute(id);
>         }
>     }
> 
>     public Object removeAttribute(final String id) {
>         if (HttpClientContext.REQUEST_CONFIG.equals(id)) {
>             RequestConfig local = this.requestConfig;
>             this.requestConfig = null;
>             return local;
>         } else {
>             return this.context.removeAttribute(id);
>         }
>     }
> 
>     public void setAttribute(final String id, final Object obj) {
>         if (HttpClientContext.REQUEST_CONFIG.equals(id)) {
>             this.requestConfig = (RequestConfig) obj;
>         } else {
>             this.context.setAttribute(id, obj);
>         }
>     }
> 
> }
> ---
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message