1010DEFAULT_SCRIPT = """
1111function main(splash)
1212 splash:init_cookies(splash.args.cookies)
13- assert( splash:go{
13+ splash:go{
1414 splash.args.url,
1515 headers=splash.args.headers,
1616 http_method=splash.args.http_method,
1717 body=splash.args.body,
18- })
19- assert(splash:wait(0.5))
18+ }
19+ local wait = tonumber(splash.args.wait or 0.5)
20+ assert(splash:wait(wait))
2021
2122 local entries = splash:history()
2223 local last_response = entries[#entries].response
@@ -94,6 +95,9 @@ def parse(self, response):
9495 resp = items [0 ]['response' ]
9596 assert resp .url == url
9697 assert resp .css ('body::text' ).get ().strip () == "hello world!"
98+ assert resp .status == resp .splash_response_status == 200
99+ assert resp .headers == resp .splash_response_headers
100+ assert resp .splash_response_headers ['Content-Type' ] == b"text/html; charset=utf-8"
97101
98102 resp2 = items [1 ]['response' ]
99103 assert resp2 .body == resp .body
@@ -118,9 +122,12 @@ def start_requests(self):
118122 assert len (items ) == 1
119123 resp = items [0 ]['response' ]
120124 assert resp .url == url + "/#foo"
125+ assert resp .status == resp .splash_response_status == 200
121126 assert resp .css ('body::text' ).get ().strip () == "hello world!"
122127 assert resp .data ['jsvalue' ] == 3
123128 assert resp .headers ['X-MyHeader' ] == b'my value'
129+ assert resp .headers ['Content-Type' ] == b'text/html'
130+ assert resp .splash_response_headers ['Content-Type' ] == b'application/json'
124131 assert resp .data ['args' ]['foo' ] == 'bar'
125132
126133
@@ -171,7 +178,6 @@ def parse_3(self, response):
171178 args = {'lua_source' : DEFAULT_SCRIPT },
172179 cookies = {'bomb' : BOMB })
173180
174-
175181 def parse_4 (self , response ):
176182 yield {'response' : response }
177183
@@ -185,19 +191,19 @@ def _cookie_dict(har_cookies):
185191
186192 # cookie should be sent to remote website, not to Splash
187193 resp = items [0 ]['response' ]
188- splash_headers = resp .request .headers
194+ splash_request_headers = resp .request .headers
189195 cookies = resp .data ['args' ]['cookies' ]
190- print (splash_headers )
196+ print (splash_request_headers )
191197 print (cookies )
192198 assert _cookie_dict (cookies ) == {
193199 # 'login': '1', # FIXME
194200 'x-set-splash' : '1'
195201 }
196- assert splash_headers .get (b'Cookie' ) is None
202+ assert splash_request_headers .get (b'Cookie' ) is None
197203
198204 # new cookie should be also sent to remote website, not to Splash
199205 resp2 = items [1 ]['response' ]
200- splash_headers = resp2 .request .headers
206+ splash_request_headers = resp2 .request .headers
201207 headers = resp2 .data ['args' ]['headers' ]
202208 cookies = resp2 .data ['args' ]['cookies' ]
203209 assert canonicalize_url (headers ['Referer' ]) == canonicalize_url (url )
@@ -206,29 +212,29 @@ def _cookie_dict(har_cookies):
206212 'x-set-splash' : '1' ,
207213 'sessionid' : 'ABCD'
208214 }
209- print (splash_headers )
215+ print (splash_request_headers )
210216 print (headers )
211217 print (cookies )
212- assert splash_headers .get (b'Cookie' ) is None
218+ assert splash_request_headers .get (b'Cookie' ) is None
213219
214220 # TODO/FIXME: Cookies fetched when working with Splash should be picked up
215221 # by Scrapy
216222 resp3 = items [2 ]['response' ]
217- splash_headers = resp3 .request .headers
218- cookie_header = splash_headers .get (b'Cookie' )
223+ splash_request_headers = resp3 .request .headers
224+ cookie_header = splash_request_headers .get (b'Cookie' )
219225 assert b'x-set-scrapy=1' in cookie_header
220226 assert b'login=1' in cookie_header
221227 assert b'x-set-splash=1' in cookie_header
222228 # assert b'sessionid=ABCD' in cookie_header # FIXME
223229
224230 # cookie bomb shouldn't cause problems
225231 resp4 = items [3 ]['response' ]
226- splash_headers = resp4 .request .headers
232+ splash_request_headers = resp4 .request .headers
227233 cookies = resp4 .data ['args' ]['cookies' ]
228234 assert _cookie_dict (cookies ) == {
229235 # 'login': '1',
230236 'x-set-splash' : '1' ,
231237 'sessionid' : 'ABCD' ,
232238 'bomb' : BOMB ,
233239 }
234- assert splash_headers .get (b'Cookie' ) is None
240+ assert splash_request_headers .get (b'Cookie' ) is None
0 commit comments