Better handling of missing content-type header in OPTIONS with entity

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1787706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2017-03-20 10:11:41 +00:00
parent e6844f5d33
commit a2927f6a04
2 changed files with 12 additions and 4 deletions

View File

@ -32,8 +32,8 @@ import java.util.Iterator;
import java.util.List;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.ClassicHttpResponse;
@ -47,7 +47,7 @@ import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
import org.apache.hc.core5.http.io.entity.HttpEntityWrapper;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.message.MessageSupport;
@ -191,7 +191,15 @@ class RequestProtocolCompliance {
private void addContentTypeHeaderIfMissing(final RoutedHttpRequest request) {
final HttpEntity entity = request.getEntity();
if (entity != null && entity.getContentType() == null) {
((AbstractHttpEntity) entity).setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
final HttpEntityWrapper entityWrapper = new HttpEntityWrapper(entity) {
@Override
public String getContentType() {
return ContentType.APPLICATION_OCTET_STREAM.getMimeType();
}
};
request.setEntity(entityWrapper);
}
}

View File

@ -32,10 +32,10 @@ import java.util.Random;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.cache.HttpCacheContext;
import org.apache.hc.client5.http.impl.sync.ClientExecChain;
import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;