Ticket #306: user-agent-306.patch
| File user-agent-306.patch, 6.1 KB (added by thijs, 5 months ago) |
|---|
-
pyamf/tests/remoting/test_client.py
4 4 # See LICENSE for details. 5 5 6 6 """ 7 Test for Remoting client.7 Tests for Remoting client. 8 8 9 9 @since: 0.1.0 10 10 """ … … 370 370 gw.connection = dc 371 371 372 372 dc.tc = self 373 dc.expected_headers = {'Content-Type': 'application/x-amf'} 373 dc.expected_headers = {'Content-Type': remoting.CONTENT_TYPE, 374 'User-Agent': client.DEFAULT_USER_AGENT} 374 375 375 376 service = gw.getService('baz', auto_execute=False) 376 377 wrapper = service.gak() 377 378 378 379 response = DummyResponse(200, '\x00\x00\x00\x00\x00\x01\x00\x0b/1/onRe' 379 380 'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello', { 380 'Content-Type': 'application/x-amf', 'Content-Length': 50})381 'Content-Type': remoting.CONTENT_TYPE, 'Content-Length': 50}) 381 382 response.tc = self 382 383 383 384 dc.expected_url = '/x/y/z' … … 392 393 393 394 response = DummyResponse(200, '\x00\x00\x00\x00\x00\x01\x00\x0b/2/onRe' 394 395 'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello', { 395 'Content-Type': 'application/x-amf'})396 'Content-Type': remoting.CONTENT_TYPE}) 396 397 response.tc = self 397 398 398 399 dc.expected_url = '/x/y/z' … … 408 409 gw.connection = dc 409 410 410 411 dc.tc = self 411 dc.expected_headers = {'Content-Type': 'application/x-amf'} 412 dc.expected_headers = {'Content-Type': remoting.CONTENT_TYPE, 413 'User-Agent': client.DEFAULT_USER_AGENT} 412 414 413 415 baz = gw.getService('baz', auto_execute=False) 414 416 spam = gw.getService('spam', auto_execute=False) … … 418 420 response = DummyResponse(200, '\x00\x00\x00\x00\x00\x02\x00\x0b/1/onRe' 419 421 'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello\x00\x0b/2/o' 420 422 'nResult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello', { 421 'Content-Type': 'application/x-amf'})423 'Content-Type': remoting.CONTENT_TYPE}) 422 424 response.tc = self 423 425 424 426 dc.expected_url = '/x/y/z' … … 436 438 gw.connection = dc 437 439 438 440 response = DummyResponse(200, '\x00\x00\x00\x00\x00\x00', { 439 'Content-Type': 'application/x-amf'})441 'Content-Type': remoting.CONTENT_TYPE}) 440 442 441 443 dc.response = response 442 444 … … 477 479 478 480 response = DummyResponse(200, '\x00\x00\x00\x01\x00\x12AppendToGatewayUrl' 479 481 '\x01\x00\x00\x00\x00\x02\x00\x05hello\x00\x00', { 480 'Content-Type': 'application/x-amf'})482 'Content-Type': remoting.CONTENT_TYPE}) 481 483 482 484 dc.response = response 483 485 … … 491 493 492 494 response = DummyResponse(200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl' 493 495 '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00', { 494 'Content-Type': 'application/x-amf'})496 'Content-Type': remoting.CONTENT_TYPE}) 495 497 496 498 dc.response = response 497 499 … … 504 506 gw.connection = dc 505 507 dc.response = DummyResponse(200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl' 506 508 '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00', { 507 'Content-Type': 'application/x-amf'})509 'Content-Type': remoting.CONTENT_TYPE}) 508 510 509 511 gw._getResponse() 510 512 self.assertTrue(dc.response.closed, True) -
pyamf/remoting/client/__init__.py
16 16 #: @see: L{ClientTypes<pyamf.ClientTypes>} 17 17 DEFAULT_CLIENT_TYPE = pyamf.ClientTypes.Flash6 18 18 19 #: Default user agent is C{PyAMF/x.x.x}. 20 DEFAULT_USER_AGENT = 'PyAMF/%s' % '.'.join(map(lambda x: str(x), pyamf.__version__)) 21 19 22 HTTP_OK = 200 20 23 21 24 def convert_args(args): … … 182 185 @type headers: L{HeaderCollection<pyamf.remoting.HeaderCollection>} 183 186 """ 184 187 185 def __init__(self, url, amf_version=pyamf.AMF0, client_type=DEFAULT_CLIENT_TYPE): 188 def __init__(self, url, amf_version=pyamf.AMF0, client_type=DEFAULT_CLIENT_TYPE, 189 user_agent=DEFAULT_USER_AGENT): 186 190 self.logger = logging.instance_logger(self) 187 191 self.original_url = url 188 192 self.requests = [] 189 193 self.request_number = 1 190 194 195 self.user_agent = user_agent 191 196 self.amf_version = amf_version 192 197 self.client_type = client_type 193 198 self.headers = remoting.HeaderCollection() … … 232 237 raise ValueError, 'Unknown scheme' 233 238 234 239 self.logger.info('Creating connection to %s://%s:%s' % (self.url[0], hostname, port)) 235 240 self.logger.debug('User-Agent: %s' % self.user_agent) 241 236 242 def addHeader(self, name, value, must_understand=False): 237 243 """ 238 244 Sets a persistent header to send with each request. … … 334 340 """ 335 341 self.logger.debug('Executing single request: %s' % request) 336 342 body = remoting.encode(self.getAMFRequest([request])) 337 343 headers = {'Content-Type': remoting.CONTENT_TYPE, 344 'User-Agent': self.user_agent} 345 338 346 self.logger.debug('Sending POST request to %s' % self._root_url) 339 347 self.connection.request('POST', self._root_url, body.getvalue(), 340 {'Content-Type': remoting.CONTENT_TYPE})348 headers) 341 349 342 350 envelope = self._getResponse() 343 351 self.removeRequest(request) … … 350 358 C{self.requests}. 351 359 """ 352 360 body = remoting.encode(self.getAMFRequest(self.requests)) 353 361 headers = {'Content-Type': remoting.CONTENT_TYPE, 362 'User-Agent': self.user_agent} 363 354 364 self.logger.debug('Sending POST request to %s' % self._root_url) 355 365 self.connection.request('POST', self._root_url, body.getvalue(), 356 {'Content-Type': remoting.CONTENT_TYPE})366 headers) 357 367 358 368 envelope = self._getResponse() 359 369
