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 package org.apache.commons.httpclient;
32
33 import junit.framework.Test;
34 import junit.framework.TestCase;
35 import junit.framework.TestSuite;
36
37 /***
38 * Tests for reading response headers.
39 *
40 * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
41 * @version $Id: TestRequestHeaders.java,v 1.5.2.1 2004/02/22 18:21:16 olegk Exp $
42 */
43 public class TestRequestHeaders extends TestCase {
44
45 HttpState state = null;
46 SimpleHttpMethod method = null;
47 HttpConnection conn = null;
48
49
50 public TestRequestHeaders(String testName) {
51 super(testName);
52 }
53
54
55 public static void main(String args[]) {
56 String[] testCaseName = {TestRequestHeaders.class.getName()};
57 junit.textui.TestRunner.main(testCaseName);
58 }
59
60
61 public static Test suite() {
62 return new TestSuite(TestRequestHeaders.class);
63 }
64
65 public void setUp() {
66 state = new HttpState();
67 method = new SimpleHttpMethod("/some/absolute/path/");
68
69 }
70
71 public void tearDown() {
72 state = null;
73 method = null;
74 conn = null;
75 }
76
77 public void testNullHeader() throws Exception {
78 conn = new SimpleHttpConnection("some.host.name", 80, "http");
79 assertEquals(null, method.getRequestHeader(null));
80 assertEquals(null, method.getRequestHeader("bogus"));
81 }
82
83 public void testHostHeaderPortHTTP80() throws Exception {
84 conn = new SimpleHttpConnection("some.host.name", 80, "http");
85 method.addRequestHeaders(state, conn);
86 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
87 }
88
89 public void testHostHeaderPortHTTP81() throws Exception {
90 conn = new SimpleHttpConnection("some.host.name", 81, "http");
91 method.addRequestHeaders(state, conn);
92 assertEquals("Host: some.host.name:81", method.getRequestHeader("Host").toString().trim());
93 }
94
95 public void testHostHeaderPortHTTPS443() throws Exception {
96 conn = new SimpleHttpConnection("some.host.name", 443, "https");
97 method.addRequestHeaders(state, conn);
98 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
99 }
100
101 public void testHostHeaderPortHTTPS444() throws Exception {
102 conn = new SimpleHttpConnection("some.host.name", 444, "https");
103 method.addRequestHeaders(state, conn);
104 assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim());
105 }
106
107 public void testHeadersPreserveCaseKeyIgnoresCase() throws Exception {
108 method.addRequestHeader(new Header("NAME", "VALUE"));
109 Header upHeader = method.getRequestHeader("NAME");
110 Header loHeader = method.getRequestHeader("name");
111 Header mixHeader = method.getRequestHeader("nAmE");
112 assertEquals("NAME", upHeader.getName());
113 assertEquals("VALUE", upHeader.getValue());
114 assertEquals("NAME", loHeader.getName());
115 assertEquals("VALUE", loHeader.getValue());
116 assertEquals("NAME", mixHeader.getName());
117 assertEquals("VALUE", mixHeader.getValue());
118 }
119 }