use of org.apache.commons.httpclient.Header in project sling by apache.
the class RangeStreamingTest method test_multiple_ranges.
public void test_multiple_ranges() throws IOException {
GetMethod get = new GetMethod(rootUrl);
get.setRequestHeader(new Header("Range", "bytes 0-9,-10"));
int status = httpClient.executeMethod(get);
assertEquals("Expect 206/PARTIAL CONTENT", 206, status);
String contentType = get.getResponseHeader("Content-Type").getValue();
assertTrue("Content Type must be multipart/byteranges", contentType.contains("multipart/byteranges"));
String boundary = contentType.substring(contentType.indexOf("boundary=") + "boundary=".length());
BufferedReader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream()));
String line = reader.readLine();
while (!("--" + boundary).equals(line)) {
line = reader.readLine();
}
assertEquals("Expected content to start with boundary", "--" + boundary, line);
assertEntityHeaders(reader, "text/plain", "bytes 0-9/79");
assertEquals("The quick ", reader.readLine());
assertEquals("Expected content to start with boundary", "--" + boundary, reader.readLine());
assertEntityHeaders(reader, "text/plain", "bytes 69-78/79");
assertEquals("corpus sic", reader.readLine());
char[] buf = new char[boundary.length() + 4];
reader.read(buf);
assertEquals("Expected content to start with boundary", "--" + boundary + "--", new String(buf));
}
use of org.apache.commons.httpclient.Header in project sling by apache.
the class HttpPingTest method testWebServerRoot.
public void testWebServerRoot() throws Exception {
// by default, the Launchpad default servlet redirects / to index.html
final String url = HTTP_BASE_URL + "/";
final GetMethod get = new GetMethod(url);
get.setFollowRedirects(false);
final int status = httpClient.executeMethod(get);
assertEquals("Status must be 302 for " + url, 302, status);
final Header h = get.getResponseHeader("Location");
assertNotNull("Location header must be provided", h);
assertTrue("Location header must end with index.html", h.getValue().endsWith("index.html"));
}
use of org.apache.commons.httpclient.Header in project sling by apache.
the class PostServletOutputContentTypeTest method runTest.
private void runTest(String acceptHeaderValue, boolean useHttpEquiv, String expectedContentType) throws Exception {
final String info = (useHttpEquiv ? "Using http-equiv parameter" : "Using Accept header") + ": ";
final String url = HTTP_BASE_URL + MY_TEST_PATH;
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
if (acceptHeaderValue != null) {
if (useHttpEquiv) {
post.addParameter(":http-equiv-accept", acceptHeaderValue);
} else {
post.addRequestHeader("Accept", acceptHeaderValue);
}
}
final int status = httpClient.executeMethod(post) / 100;
assertEquals(info + "Expected status 20x for POST at " + url, 2, status);
final Header h = post.getResponseHeader("Content-Type");
assertNotNull(info + "Expected Content-Type header", h);
final String ct = h.getValue();
assertTrue(info + "Expected Content-Type '" + expectedContentType + "' for Accept header=" + acceptHeaderValue + " but got '" + ct + "'", ct.startsWith(expectedContentType));
}
use of org.apache.commons.httpclient.Header in project sling by apache.
the class AuthenticationResponseCodeTest method testWithNonHtmlAcceptHeaderIncorrectCredentials.
@Test
public void testWithNonHtmlAcceptHeaderIncorrectCredentials() throws Exception {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("j_username", "garbage"));
params.add(new NameValuePair("j_password", "garbage"));
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("User-Agent", "Mozilla/5.0 Sling Integration Test"));
assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, headers, null);
}
use of org.apache.commons.httpclient.Header in project sling by apache.
the class AuthenticationResponseCodeTest method testValidatingIncorrectCookie.
@Test
public void testValidatingIncorrectCookie() throws Exception {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("j_validate", "true"));
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("Cookie", "sling.formauth=garbage"));
HttpMethod post = assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_FORBIDDEN, params, headers, null);
assertXReason(post);
}
Aggregations