def post_url(self, url, data='', headers=None, files=None, connect_timeout=0.5, request_timeout=2, follow_redirects=True, content_type=None, callback=None, request_types=None): placeholder = future.Placeholder() request = frontik.util.make_post_request( url, data, {} if headers is None else headers, {} if files is None else files, connect_timeout, request_timeout, follow_redirects, content_type) self.fetch_request( request, partial(self._fetch_request_response, placeholder, callback, request, request_types=request_types)) return placeholder
def get_url(self, url, data=None, headers=None, connect_timeout=0.5, request_timeout=2, callback=None, follow_redirects=True, request_types=None, labels=None): placeholder = future.Placeholder() request = frontik.util.make_get_request( url, {} if data is None else data, {} if headers is None else headers, connect_timeout, request_timeout, follow_redirects) self.fetch_request( request, partial(self._fetch_request_response, placeholder, callback, request, request_types=request_types, labels=labels)) return placeholder
def get_url_retry(self, url, data=dict(), headers=dict(), retry_count=3, retry_delay=0.1, connect_timeout=0.5, request_timeout=2, callback=None, request_types=None): placeholder = future.Placeholder() request = frontik.util.make_get_request( url, {} if data is None else data, {} if headers is None else headers, connect_timeout, request_timeout) def step1(retry_count, response): if response.error and retry_count > 0: self.log.warn('failed to get %s; retries left = %s; retrying', response.effective_url, retry_count) # TODO use handler-specific ioloop if retry_delay > 0: tornado.ioloop.IOLoop.instance().add_timeout( time.time() + retry_delay, self.finish_group.add( self.async_callback(partial(step2, retry_count)))) else: step2(retry_count) else: if response.error and retry_count == 0: self.log.warn( 'failed to get %s; no more retries left; give up retrying', response.effective_url) self._fetch_request_response(placeholder, callback, request, response, request_types=request_types) def step2(retry_count): self.http_client.fetch( request, self.finish_group.add( self.async_callback(partial(step1, retry_count - 1)))) self.http_client.fetch( request, self.finish_group.add( self.async_callback(partial(step1, retry_count - 1)))) return placeholder
def put_url(self, url, data='', headers=None, connect_timeout=0.5, request_timeout=2, callback=None, request_types=None): placeholder = future.Placeholder() request = frontik.util.make_put_request( url, data, {} if headers is None else headers, connect_timeout, request_timeout) self.fetch_request( request, partial(self._fetch_request_response, placeholder, callback, request, request_types=request_types)) return placeholder