@@ -51,7 +51,7 @@ test('makes a HTTP request (without proxy)', async (t) => {
51
51
} ) ;
52
52
53
53
test ( 'proxies a GET request' , async ( t ) => {
54
- t . plan ( 2 ) ;
54
+ t . plan ( 3 ) ;
55
55
56
56
const requestHandler = sinon . stub ( ) . callsFake ( ( incomingRequest , outgoingRequest ) => {
57
57
outgoingRequest . end ( 'foo' ) ;
@@ -74,14 +74,57 @@ test('proxies a GET request', async (t) => {
74
74
httpProxyServer . url ,
75
75
) ;
76
76
77
- const response = await page . goto ( httpServer . url ) ;
77
+ const response = await page . goto ( httpServer . url + '/foo' ) ;
78
78
79
79
t . is ( ( await response . headers ( ) ) [ 'x-foo' ] , 'bar' ) ;
80
+
81
+ t . is ( await page . url ( ) , httpServer . url + '/foo' ) ;
80
82
} ) ;
81
83
82
84
t . true ( requestHandler . called ) ;
83
85
} ) ;
84
86
87
+ test ( 'Puppeteer handles redirects' , async ( t ) => {
88
+ t . plan ( 1 ) ;
89
+
90
+ let requestIndex = 0 ;
91
+
92
+ const requestHandler = sinon
93
+ . stub ( )
94
+ . callsFake ( ( incomingRequest , outgoingRequest ) => {
95
+ if ( ++ requestIndex < 3 ) {
96
+ outgoingRequest . writeHead ( 301 , {
97
+ location : '/' + requestIndex ,
98
+ } ) ;
99
+ outgoingRequest . end ( ) ;
100
+ } else {
101
+ outgoingRequest . end ( String ( requestIndex ) ) ;
102
+ }
103
+ } ) ;
104
+
105
+ const httpServer = await createHttpServer ( requestHandler ) ;
106
+
107
+ const httpProxyServer = await createHttpProxyServer ( ) ;
108
+
109
+ await createPage ( async ( page ) => {
110
+ const pageProxy = createPageProxy ( {
111
+ page,
112
+ } ) ;
113
+
114
+ await page . setRequestInterception ( true ) ;
115
+
116
+ proxyRequest (
117
+ page ,
118
+ pageProxy ,
119
+ httpProxyServer . url ,
120
+ ) ;
121
+
122
+ await page . goto ( httpServer . url ) ;
123
+ } ) ;
124
+
125
+ t . is ( requestHandler . callCount , 3 ) ;
126
+ } ) ;
127
+
85
128
test ( 'handles HTTP errors (unreachable server)' , async ( t ) => {
86
129
t . plan ( 2 ) ;
87
130
0 commit comments