1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient;
33
34 import org.apache.commons.httpclient.protocol.Protocol;
35
36 import junit.framework.Test;
37 import junit.framework.TestCase;
38 import junit.framework.TestSuite;
39
40 /***
41 * Tests for reading response headers.
42 *
43 * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
44 * @version $Id: TestRequestHeaders.java 608014 2008-01-02 05:48:53Z rolandw $
45 */
46 public class TestRequestHeaders extends TestCase {
47
48
49 public TestRequestHeaders(String testName) {
50 super(testName);
51 }
52
53
54 public static void main(String args[]) {
55 String[] testCaseName = {TestRequestHeaders.class.getName()};
56 junit.textui.TestRunner.main(testCaseName);
57 }
58
59
60 public static Test suite() {
61 return new TestSuite(TestRequestHeaders.class);
62 }
63
64 public void testNullHeader() throws Exception {
65 FakeHttpMethod method = new FakeHttpMethod();
66 assertEquals(null, method.getRequestHeader(null));
67 assertEquals(null, method.getRequestHeader("bogus"));
68 }
69
70 public void testHostHeaderPortHTTP80() throws Exception {
71 HttpConnection conn = new HttpConnection("some.host.name", 80);
72 HttpState state = new HttpState();
73 FakeHttpMethod method = new FakeHttpMethod();
74 method.addRequestHeaders(state, conn);
75 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
76 }
77
78 public void testHostHeaderPortHTTP81() throws Exception {
79 HttpConnection conn = new HttpConnection("some.host.name", 81);
80 HttpState state = new HttpState();
81 FakeHttpMethod method = new FakeHttpMethod();
82 method.addRequestHeaders(state, conn);
83 assertEquals("Host: some.host.name:81", method.getRequestHeader("Host").toString().trim());
84 }
85
86 public void testHostHeaderPortHTTPS443() throws Exception {
87 HttpConnection conn = new HttpConnection("some.host.name", 443,
88 Protocol.getProtocol("https"));
89 HttpState state = new HttpState();
90 FakeHttpMethod method = new FakeHttpMethod();
91 method.addRequestHeaders(state, conn);
92 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
93 }
94
95 public void testHostHeaderPortHTTPS444() throws Exception {
96 HttpConnection conn = new HttpConnection("some.host.name", 444,
97 Protocol.getProtocol("https"));
98 HttpState state = new HttpState();
99 FakeHttpMethod method = new FakeHttpMethod();
100 method.addRequestHeaders(state, conn);
101 assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim());
102 }
103
104 public void testHeadersPreserveCaseKeyIgnoresCase() throws Exception {
105 FakeHttpMethod method = new FakeHttpMethod();
106 method.addRequestHeader(new Header("NAME", "VALUE"));
107 Header upHeader = method.getRequestHeader("NAME");
108 Header loHeader = method.getRequestHeader("name");
109 Header mixHeader = method.getRequestHeader("nAmE");
110 assertEquals("NAME", upHeader.getName());
111 assertEquals("VALUE", upHeader.getValue());
112 assertEquals("NAME", loHeader.getName());
113 assertEquals("VALUE", loHeader.getValue());
114 assertEquals("NAME", mixHeader.getName());
115 assertEquals("VALUE", mixHeader.getValue());
116 }
117 }