use of org.eclipse.jetty.client.HttpResponse 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.HttpResponse in project jetty.project by eclipse.
the class HttpChannelOverHTTP method exchangeTerminating.
@Override
public Result exchangeTerminating(HttpExchange exchange, Result result) {
if (result.isFailed())
return result;
HttpResponse response = exchange.getResponse();
if ((response.getVersion() == HttpVersion.HTTP_1_1) && (response.getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101)) {
String connection = response.getHeaders().get(HttpHeader.CONNECTION);
if ((connection == null) || !connection.toLowerCase(Locale.US).contains("upgrade")) {
return new Result(result, new HttpResponseException("101 Switching Protocols without Connection: Upgrade not supported", response));
}
// Upgrade Response
HttpRequest request = exchange.getRequest();
if (request instanceof HttpConnectionUpgrader) {
HttpConnectionUpgrader listener = (HttpConnectionUpgrader) request;
try {
listener.upgrade(response, getHttpConnection());
} catch (Throwable x) {
return new Result(result, x);
}
}
}
return result;
}
use of org.eclipse.jetty.client.HttpResponse in project jetty.project by eclipse.
the class HttpReceiverOverHTTP2 method onHeaders.
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
HttpExchange exchange = getHttpExchange();
if (exchange == null)
return;
HttpResponse response = exchange.getResponse();
MetaData.Response metaData = (MetaData.Response) frame.getMetaData();
response.version(metaData.getHttpVersion()).status(metaData.getStatus()).reason(metaData.getReason());
if (responseBegin(exchange)) {
HttpFields headers = metaData.getFields();
for (HttpField header : headers) {
if (!responseHeader(exchange, header))
return;
}
if (responseHeaders(exchange)) {
int status = metaData.getStatus();
boolean informational = HttpStatus.isInformational(status) && status != HttpStatus.SWITCHING_PROTOCOLS_101;
if (frame.isEndStream() || informational)
responseSuccess(exchange);
}
}
}
Aggregations