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