use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testFoldedHeaders.
public void testFoldedHeaders() throws Exception {
final String body = "XXX\r\nYYY\r\nZZZ";
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 200 OK");
out.println("Connection: close");
out.println("Content-Length: " + body.length());
out.println("Content-Type: text/xml; charset=utf-8");
out.println("\tboundary=XXXX");
out.println("Date: Wed, 28 Mar 2001");
out.println(" 05:05:04 GMT");
out.println("Server: UserLand Frontier/7.0-WinNT");
out.println();
out.println(body);
out.flush();
return true;
}
});
HttpMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals("close", method.getResponseHeader("Connection").getValue());
assertEquals(body.length(), Integer.parseInt(method.getResponseHeader("Content-Length").getValue()));
assertEquals("text/xml; charset=utf-8 boundary=XXXX", method.getResponseHeader("Content-Type").getValue());
assertEquals("Wed, 28 Mar 2001 05:05:04 GMT", method.getResponseHeader("Date").getValue());
assertEquals("UserLand Frontier/7.0-WinNT", method.getResponseHeader("Server").getValue());
assertTrue(method.getResponseHeader("Content-Type").toString().indexOf("boundary") != -1);
}
use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testProxyNoContentLength.
public void testProxyNoContentLength() throws Exception {
// test with proxy-connection header
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 200 OK");
out.println("proxy-connection: keep-alive");
out.println();
out.println("12345");
out.flush();
return true;
}
});
client.getHostConfiguration().setProxy(server.getLocalAddress(), server.getLocalPort());
GetMethod method = new GetMethod("/");
client.executeMethod(method);
method.getResponseBodyAsString();
assertFalse(connectionManager.getConection().isOpen());
// test without proxy-connection header
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 200 OK");
out.println();
out.println("12345");
out.flush();
return true;
}
});
method = new GetMethod("/");
client.executeMethod(method);
method.getResponseBodyAsString();
assertFalse(connectionManager.getConection().isOpen());
}
use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testForceCloseConnection.
public void testForceCloseConnection() throws Exception {
this.server.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
ResponseWriter out = conn.getWriter();
out.println("HTTP/1.1 200 OK");
out.println("Content-Type: garbage");
out.println();
out.println("stuff");
out.flush();
return true;
}
});
FakeHttpMethod method = new FakeHttpMethod();
client.executeMethod(method);
assertTrue("Connection should be closed", method.shouldCloseConnection(connectionManager.getConection()));
assertTrue("Connection should be force-closed", method.isConnectionCloseForced());
}
use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testNullHeaders.
public void testNullHeaders() throws Exception {
this.server.setHttpService(new HttpService() {
public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
response.addHeader(new Header("Connection", "close"));
response.setBodyString("XXX\r\nYYY\r\nZZZ");
return true;
}
});
HttpMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals(null, method.getResponseHeader(null));
assertEquals(null, method.getResponseHeader("bogus"));
}
use of org.apache.commons.httpclient.server.SimpleRequest in project ecf by eclipse.
the class TestResponseHeaders method testInvalidContentLength2.
public void testInvalidContentLength2() throws Exception {
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", "stuff"));
response.addHeader(new Header("Content-Length", "5"));
response.setBodyString("12345");
return true;
}
});
GetMethod method = new GetMethod("/");
client.executeMethod(method);
assertEquals(5, method.getResponseContentLength());
}
Aggregations