Search in sources :

Example 6 with HttpService

use of org.apache.commons.httpclient.server.HttpService in project ecf by eclipse.

the class TestResponseHeaders method testDuplicateContentLength.

/**
 * Tests that having a duplicate content length causes no problems.
 */
public void testDuplicateContentLength() throws Exception {
    final String body = "XXX\r\nYYY\r\nZZZ";
    this.server.setHttpService(new HttpService() {

        public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
            response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
            response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
            response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
            response.setBodyString(body);
            return true;
        }
    });
    HttpMethod method = new GetMethod();
    client.executeMethod(method);
    assertNotNull("Response body is null.", method.getResponseBodyAsStream());
}
Also used : HttpService(org.apache.commons.httpclient.server.HttpService) SimpleResponse(org.apache.commons.httpclient.server.SimpleResponse) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 HttpService (org.apache.commons.httpclient.server.HttpService)6 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)6 SimpleResponse (org.apache.commons.httpclient.server.SimpleResponse)6