public SlingHttpResponse doStreamRequest()

in src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java [313:345]


    public SlingHttpResponse doStreamRequest(HttpUriRequest request, List<Header> headers, int... expectedStatus)
            throws ClientException {
        // create context from config
        HttpClientContext context = createHttpClientContextFromConfig();
        context.setAttribute(EXPECTED_STATUS, expectedStatus);

        // add headers
        if (headers != null) {
            request.setHeaders(headers.toArray(new Header[headers.size()]));
        }
        SlingHttpResponse response = null;
        try {
            log.debug("request {} {}", request.getMethod(), request.getURI());
            response = new SlingHttpResponse(this.execute(request, context));
            log.debug("response {}", HttpUtils.getHttpStatus(response));
            // Check the status and throw a ClientException if it doesn't match expectedStatus, but close the entity before
            if (expectedStatus != null && expectedStatus.length > 0) {
                try {
                    HttpUtils.verifyHttpStatus(response, expectedStatus);
                } catch (ClientException e) {
                    // catch the exception to make sure we close the entity before re-throwing it
                    response.close();
                    e.setRequest(request);
                    e.setResponse(response);
                    throw e;
                }
            }

            return response;
        } catch (IOException e) {
            throw new TestingIOException("Could not execute http request", e, request, response);
        }
    }