use of org.apache.http.HttpEntityEnclosingRequest in project android_frameworks_base by ParanoidAndroid.
the class Request method sendRequest.
/**
* Send the request line and headers
*/
void sendRequest(AndroidHttpClientConnection httpClientConnection) throws HttpException, IOException {
// don't send cancelled requests
if (mCancelled)
return;
if (HttpLog.LOGV) {
HttpLog.v("Request.sendRequest() " + mHost.getSchemeName() + "://" + getHostPort());
// HttpLog.v(mHttpRequest.getRequestLine().toString());
if (false) {
Iterator i = mHttpRequest.headerIterator();
while (i.hasNext()) {
Header header = (Header) i.next();
HttpLog.v(header.getName() + ": " + header.getValue());
}
}
}
requestContentProcessor.process(mHttpRequest, mConnection.getHttpContext());
httpClientConnection.sendRequestHeader(mHttpRequest);
if (mHttpRequest instanceof HttpEntityEnclosingRequest) {
httpClientConnection.sendRequestEntity((HttpEntityEnclosingRequest) mHttpRequest);
}
if (HttpLog.LOGV) {
HttpLog.v("Request.requestSent() " + mHost.getSchemeName() + "://" + getHostPort() + mPath);
}
}
use of org.apache.http.HttpEntityEnclosingRequest in project robovm by robovm.
the class HttpService method handleRequest.
public void handleRequest(final HttpServerConnection conn, final HttpContext context) throws IOException, HttpException {
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
HttpResponse response = null;
try {
HttpRequest request = conn.receiveRequestHeader();
request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
// Downgrade protocol version if greater than HTTP/1.1
ver = HttpVersion.HTTP_1_1;
}
if (request instanceof HttpEntityEnclosingRequest) {
if (((HttpEntityEnclosingRequest) request).expectContinue()) {
response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context);
response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
if (this.expectationVerifier != null) {
try {
this.expectationVerifier.verify(request, response, context);
} catch (HttpException ex) {
response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
handleException(ex, response);
}
}
if (response.getStatusLine().getStatusCode() < 200) {
// Send 1xx response indicating the server expections
// have been met
conn.sendResponseHeader(response);
conn.flush();
response = null;
conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
}
} else {
conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
}
}
if (response == null) {
response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
this.processor.process(request, context);
doService(request, response, context);
}
// Make sure the request content is fully consumed
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null) {
entity.consumeContent();
}
}
} catch (HttpException ex) {
response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
handleException(ex, response);
}
this.processor.process(response, context);
conn.sendResponseHeader(response);
conn.sendResponseEntity(response);
conn.flush();
if (!this.connStrategy.keepAlive(response, context)) {
conn.close();
}
}
use of org.apache.http.HttpEntityEnclosingRequest in project robovm by robovm.
the class RequestContent method process.
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (request instanceof HttpEntityEnclosingRequest) {
if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
throw new ProtocolException("Transfer-encoding header already present");
}
if (request.containsHeader(HTTP.CONTENT_LEN)) {
throw new ProtocolException("Content-Length header already present");
}
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity == null) {
request.addHeader(HTTP.CONTENT_LEN, "0");
return;
}
// Must specify a transfer encoding or a content length
if (entity.isChunked() || entity.getContentLength() < 0) {
if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
throw new ProtocolException("Chunked transfer encoding not allowed for " + ver);
}
request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
} else {
request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
}
// Specify a content type if known
if (entity.getContentType() != null && !request.containsHeader(HTTP.CONTENT_TYPE)) {
request.addHeader(entity.getContentType());
}
// Specify a content encoding if known
if (entity.getContentEncoding() != null && !request.containsHeader(HTTP.CONTENT_ENCODING)) {
request.addHeader(entity.getContentEncoding());
}
}
}
use of org.apache.http.HttpEntityEnclosingRequest in project pinpoint by naver.
the class HttpRequestExecutorExecuteMethodInterceptor method recordEntity.
protected void recordEntity(HttpMessage httpMessage, Trace trace) {
if (httpMessage instanceof HttpEntityEnclosingRequest) {
final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage;
try {
final HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
final String entityString = entityUtilsToString(entity, "UTF8", 1024);
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
}
}
} catch (Exception e) {
logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
}
}
}
use of org.apache.http.HttpEntityEnclosingRequest in project spring-framework by spring-projects.
the class HttpComponentsStreamingClientHttpRequest method executeInternal.
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers);
if (this.httpRequest instanceof HttpEntityEnclosingRequest && body != null) {
HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
HttpEntity requestEntity = new StreamingHttpEntity(getHeaders(), body);
entityEnclosingRequest.setEntity(requestEntity);
}
HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
return new HttpComponentsClientHttpResponse(httpResponse);
}
Aggregations