Request getRequest(final ClientRequest cr) {
final String strMethod = cr.getMethod();
final URI uri = cr.getURI();
RequestBuilder builder = new RequestBuilder(strMethod).setUrl(uri.toString());
final Request.EntityWriter entity = getHttpEntity(cr);
if(entity != null) {
builder = builder.setBody(entity);
}
ProxyServer proxyServer = createProxyServer(cr);
if(proxyServer != null)
builder.setProxyServer(proxyServer);
if(this.clientConfig != null) {
if(!this.clientConfig.getPropertyAsFeature(NonBlockingClientConfig.PROPERTY_DISABLE_COOKIES)) {
for(Cookie cookie : cookieStore.get())
builder = builder.addCookie(cookie);
cookieStore.remove();
}
if(this.clientConfig.getPropertyAsFeature(ClientConfig.PROPERTY_FOLLOW_REDIRECTS))
builder = builder.setFollowRedirects(true);
else
builder = builder.setFollowRedirects(false);
}
Request request = builder.build();
// /* extremely ugly, unnecessary and inefficient. Unfortunately it is needed
// because client side providers which modifies header values when entity is
// being written. Ning Client writes is too late, so header is ClientRequest is
// not yet changed and not propagated into Nings Request.