Search in sources :

Example 1 with HttpResponse

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));
    }
}
Also used : HttpExchange(org.eclipse.jetty.client.HttpExchange) HttpResponse(org.eclipse.jetty.client.HttpResponse) HttpResponseException(org.eclipse.jetty.client.HttpResponseException)

Example 2 with HttpResponse

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;
}
Also used : HttpRequest(org.eclipse.jetty.client.HttpRequest) HttpResponse(org.eclipse.jetty.client.HttpResponse) HttpResponseException(org.eclipse.jetty.client.HttpResponseException) Result(org.eclipse.jetty.client.api.Result)

Example 3 with HttpResponse

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);
        }
    }
}
Also used : Response(org.eclipse.jetty.client.api.Response) HttpResponse(org.eclipse.jetty.client.HttpResponse) MetaData(org.eclipse.jetty.http.MetaData) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields) HttpExchange(org.eclipse.jetty.client.HttpExchange) HttpResponse(org.eclipse.jetty.client.HttpResponse)

Aggregations

HttpResponse (org.eclipse.jetty.client.HttpResponse)3 HttpExchange (org.eclipse.jetty.client.HttpExchange)2 HttpResponseException (org.eclipse.jetty.client.HttpResponseException)2 HttpRequest (org.eclipse.jetty.client.HttpRequest)1 Response (org.eclipse.jetty.client.api.Response)1 Result (org.eclipse.jetty.client.api.Result)1 HttpField (org.eclipse.jetty.http.HttpField)1 HttpFields (org.eclipse.jetty.http.HttpFields)1 MetaData (org.eclipse.jetty.http.MetaData)1