use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method messageComplete.
@Override
public boolean messageComplete() {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return false;
boolean proceed = responseSuccess(exchange);
if (!proceed)
return true;
int status = exchange.getResponse().getStatus();
if (status == HttpStatus.SWITCHING_PROTOCOLS_101)
return true;
if (HttpMethod.CONNECT.is(exchange.getRequest().getMethod()) && status == HttpStatus.OK_200)
return true;
return false;
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method startResponse.
@Override
public boolean startResponse(HttpVersion version, int status, String reason) {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return false;
String method = exchange.getRequest().getMethod();
parser.setHeadResponse(HttpMethod.HEAD.is(method) || (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200));
exchange.getResponse().version(version).status(status).reason(reason);
return !responseBegin(exchange);
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method badMessage.
@Override
public void badMessage(int status, String reason) {
HttpExchange exchange = getHttpExchange();
if (exchange != null) {
HttpResponse response = exchange.getResponse();
response.status(status).reason(reason);
failAndClose(new HttpResponseException("HTTP protocol violation: bad response on " + getHttpConnection(), response));
}
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTP method content.
@Override
public boolean content(ByteBuffer buffer) {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return false;
CompletableCallback callback = new CompletableCallback() {
@Override
public void resume() {
if (LOG.isDebugEnabled())
LOG.debug("Content consumed asynchronously, resuming processing");
process();
}
public void abort(Throwable x) {
failAndClose(x);
}
};
// Do not short circuit these calls.
boolean proceed = responseContent(exchange, buffer, callback);
boolean async = callback.tryComplete();
return !proceed || async;
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method newExchange.
protected HttpExchange newExchange() {
HttpRequest request = (HttpRequest) client.newRequest("http://localhost");
FutureResponseListener listener = new FutureResponseListener(request);
HttpExchange exchange = new HttpExchange(destination, request, Collections.<Response.ResponseListener>singletonList(listener));
boolean associated = connection.getHttpChannel().associate(exchange);
Assert.assertTrue(associated);
exchange.requestComplete(null);
exchange.terminateRequest();
return exchange;
}
Aggregations