19
19
20
20
import static java .net .HttpURLConnection .HTTP_OK ;
21
21
import static java .nio .charset .StandardCharsets .UTF_8 ;
22
+ import static org .junit .Assert .assertEquals ;
23
+ import static org .junit .Assert .assertNull ;
22
24
23
25
import com .google .common .io .ByteStreams ;
24
26
32
34
import org .openqa .selenium .net .PortProber ;
33
35
import org .openqa .selenium .remote .http .HttpMethod ;
34
36
import org .openqa .selenium .remote .http .HttpRequest ;
37
+ import org .openqa .selenium .remote .http .HttpResponse ;
35
38
36
39
import java .io .IOException ;
37
40
import java .io .InputStream ;
@@ -57,31 +60,31 @@ public void stopServer() {
57
60
}
58
61
59
62
@ Test
60
- public void shouldForwardRequestsToEndPoint () {
61
- // SessionCodec handler = new Passthrough(server.url);
62
- // FakeHttpServletRequest req = new FakeHttpServletRequest(" GET", new UrlInfo(server.url.toString(), "", " /ok") );
63
- // req.addHeader("X-Cheese", "Cake");
64
- // FakeHttpServletResponse resp = new FakeHttpServletResponse ();
65
- // handler.handle(req, resp);
66
- //
67
- // // HTTP headers are case insensitive. This is how the HttpUrlConnection likes to encode things
68
- // assertEquals("Cake", server.lastRequest.getHeader("x-cheese"));
63
+ public void shouldForwardRequestsToEndPoint () throws IOException {
64
+ SessionCodec handler = new Passthrough (server .url );
65
+ HttpRequest req = new HttpRequest ( HttpMethod . GET , " /ok" );
66
+ req .addHeader ("X-Cheese" , "Cake" );
67
+ HttpResponse resp = new HttpResponse ();
68
+ handler .handle (req , resp );
69
+
70
+ // HTTP headers are case insensitive. This is how the HttpUrlConnection likes to encode things
71
+ assertEquals ("Cake" , server .lastRequest .getHeader ("x-cheese" ));
69
72
}
70
73
71
74
@ Test
72
- public void shouldStripKeepAliveHeader () {
73
- // SessionCodec handler = new Passthrough(server.url);
74
- // FakeHttpServletRequest req = new FakeHttpServletRequest(" GET", new UrlInfo(server.url.toString(), "", " /ok") );
75
- // req.addHeader("Keep-Alive", "timeout=600");
76
- // req.addHeader("Connection", "Keep-Alive, Upgrade");
77
- // FakeHttpServletResponse resp = new FakeHttpServletResponse ();
78
- // handler.handle(req, resp);
79
- //
80
- // assertNull(server.lastRequest.getHeader("keep-alive"));
81
- // // Not, we must set the connection to `close` in order to have the JVM avoid attempting to keep
82
- // // the url connection open.
83
- // // http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html
84
- // assertEquals("close", server.lastRequest.getHeader("connection"));
75
+ public void shouldStripKeepAliveHeader () throws IOException {
76
+ SessionCodec handler = new Passthrough (server .url );
77
+ HttpRequest req = new HttpRequest ( HttpMethod . GET , " /ok" );
78
+ req .addHeader ("Keep-Alive" , "timeout=600" );
79
+ req .addHeader ("Connection" , "Keep-Alive, Upgrade" );
80
+ HttpResponse resp = new HttpResponse ();
81
+ handler .handle (req , resp );
82
+
83
+ assertNull (server .lastRequest .getHeader ("keep-alive" ));
84
+ // Not, we must set the connection to `close` in order to have the JVM avoid attempting to keep
85
+ // the url connection open.
86
+ // http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html
87
+ assertEquals ("close" , server .lastRequest .getHeader ("connection" ));
85
88
}
86
89
87
90
private static class Server {
0 commit comments