Fixes #4808 - Review HttpClient Request header APIs.

Updates after review.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2020-05-08 17:52:27 +02:00
parent a93b2c6084
commit b6c6684c70
5 changed files with 10 additions and 8 deletions

View File

@ -472,7 +472,7 @@ public class HttpClient extends ContainerLifeCycle
continue;
if (!newRequest.getHeaders().contains(field))
newRequest.header(field);
newRequest.addHeader(field);
}
return newRequest;
}

View File

@ -153,7 +153,7 @@ public abstract class HttpConnection implements IConnection
if (version.getVersion() <= 11)
{
if (!headers.contains(HttpHeader.HOST))
request.header(getHttpDestination().getHostField());
request.addHeader(getHttpDestination().getHostField());
}
// Add content headers
@ -172,14 +172,14 @@ public abstract class HttpConnection implements IConnection
if (contentType != null)
{
HttpField field = new HttpField(HttpHeader.CONTENT_TYPE, contentType);
request.header(field);
request.addHeader(field);
}
}
long contentLength = content.getLength();
if (contentLength >= 0)
{
if (!headers.contains(HttpHeader.CONTENT_LENGTH))
request.header(new HttpField.LongValueHttpField(HttpHeader.CONTENT_LENGTH, contentLength));
request.addHeader(new HttpField.LongValueHttpField(HttpHeader.CONTENT_LENGTH, contentLength));
}
}
@ -194,7 +194,7 @@ public abstract class HttpConnection implements IConnection
if (cookies != null)
{
HttpField cookieField = new HttpField(HttpHeader.COOKIE, cookies.toString());
request.header(cookieField);
request.addHeader(cookieField);
}
}

View File

@ -242,7 +242,7 @@ public abstract class HttpReceiver
boolean process = notifier.notifyHeader(exchange.getConversation().getResponseListeners(), response, field);
if (process)
{
response.header(field);
response.addHeader(field);
HttpHeader fieldHeader = field.getHeader();
if (fieldHeader != null)
{

View File

@ -307,6 +307,7 @@ public class HttpRequest implements Request
}
@Override
@Deprecated
public Request header(String name, String value)
{
if (value == null)
@ -317,6 +318,7 @@ public class HttpRequest implements Request
}
@Override
@Deprecated
public Request header(HttpHeader header, String value)
{
if (value == null)
@ -382,7 +384,7 @@ public class HttpRequest implements Request
return this;
}
public HttpRequest header(HttpField header)
public HttpRequest addHeader(HttpField header)
{
headers.add(header);
return this;

View File

@ -92,7 +92,7 @@ public class HttpResponse implements Response
return headers.asImmutable();
}
public HttpResponse header(HttpField header)
public HttpResponse addHeader(HttpField header)
{
headers.add(header);
return this;