if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
// Do not send the expect header if request body is known to be empty
if (entity != null && entity.getContentLength() != 0) {
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
if (HttpProtocolParams.useExpectContinue(request.getParams())
&& !ver.lessEquals(HttpVersion.HTTP_1_0)) {
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
}
}