hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HttpContext and RequestConfig
Date Wed, 15 Oct 2014 14:30:53 GMT
On Wed, 2014-10-15 at 09:50 -0400, Todd W Lainhart wrote:
> > 
> > What one might do instead of cloning a context is to wrap it with a
> > decorator and discard the decorator along with all local modifications.
> > 
> 
> Thanks.  I'll have to think on this - I'm not sure that it will solve this 
> problem.  The problem is that I want the HttpContext passed between 
> execute(...) invocations to maintain/accumulate state for those 
> invocations (e.g. cookies, redirects list) - just not inherit the 
> RequestConfig state on individual requests where it's been applied.
> 
>   -- Todd

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
View raw message