def request(url, callback, content='', headers=None, method='GET', timeout=5.0, close=True, ssl_args=None, compress=False, recv_len=None, event=None): ''' make an async http request When operating a tcpserver.SERVER, use this method to make async HTTP requests that eventually finish with a success or error call to a RequestCallback instance. The timeout feature will not work unless TIMERS.service is being called with appropriate frequency. Parameters: url : resource url callback: a type of RequestCallback to which asynchronous results are reported content : http content to send headers : dictionary of http headers method : http method timeout : max time, in seconds, allowed for network inactivity close : close socket after request complete, boolean ssl_args: dict of kwargs for add_connection recv_len: read buffer size (default = BasicHandler.RECV_LEN) event : dictionary of Handler event callback routines on_init(handler) on_open(handler) on_close(handler) on_handshake(handler, cert): bool, True means keep going on_ready(handler) on_http_headers(handler): (rc, result), (0, None) means keep going on_http_send(handler, headers, content) on_data(handler, data) ''' url = _URLParser(url) context = _Context(host=url.host, resource=url.resource, callback=callback, content=content, headers=headers, method=method, timeout=timeout, close=close, compress=compress, recv_len=recv_len, event=event) if url.is_ssl: ssl = {'ssl': True} if ssl_args: ssl.update(ssl_args) else: ssl = {'ssl': False} SERVER.add_connection((url.address, url.port), _Handler, context, **ssl)
def connect_parsed( callback, url, host, address, port, path, query, is_ssl, method, headers, body, is_json, is_form, timeout, wrapper, handler, evaluate, debug, trace, **kwargs ): c = ConnectContext(callback, url, method, path, query, host, headers, body, is_json, is_form, timeout, wrapper, evaluate, debug, trace, kwargs) return SERVER.add_connection((address, port), handler or ConnectHandler, context=c, ssl=is_ssl)
def connect_parsed(callback, url, host, address, port, path, query, is_ssl, method, headers, body, is_json, is_form, timeout, wrapper, handler, evaluate, debug, trace, **kwargs): c = ConnectContext(callback, url, method, path, query, host, headers, body, is_json, is_form, timeout, wrapper, evaluate, debug, trace, kwargs) return SERVER.add_connection((address, port), handler or ConnectHandler, context=c, ssl=is_ssl)
def _connect(callback, url, host, address, port, path, is_ssl, method, body, headers, is_json, is_debug, timeout, wrapper, setup, handler, trace, kwargs): c = ConnectContext(callback, url, method, path, host, headers, body, is_json, is_debug, timeout, wrapper, setup, kwargs, trace) return SERVER.add_connection( (address, port), ConnectHandler if handler is None else handler, c, ssl=is_ssl)
def request(url, callback, content='', headers=None, method='GET', timeout=5.0, close=True, ssl_args=None, compress=False, recv_len=None, event=None): ''' make an async http request When operating a tcpserver.SERVER, use this method to make async HTTP requests that eventually finish with a success or error call to a RequestCallback instance. The timeout feature will not work unless TIMERS.service is being called with appropriate frequency. Parameters: url : resource url callback: a type of RequestCallback to which asynchronous results are reported content : http content to send headers : dictionary of http headers method : http method timeout : max time, in seconds, allowed for network inactivity close : close socket after request complete, boolean ssl_args: dict of kwargs for add_connection recv_len: read buffer size (default = BasicHandler.RECV_LEN) event : dictionary of Handler event callback routines on_init(handler) on_open(handler) on_close(handler) on_handshake(handler, cert): bool, True means keep going on_ready(handler) on_http_headers(handler): (rc, result), (0, None) means keep going on_http_send(handler, headers, content) on_data(handler, data) ''' url = _URLParser(url) context = _Context(host=url.host, resource=url.resource, callback=callback, content=content, headers=headers, method=method, timeout=timeout, close=close, compress=compress, recv_len=recv_len, event=event) if url.is_ssl: ssl = {'ssl': True} if ssl_args: ssl.update(ssl_args) else: ssl = {'ssl': False} SERVER.add_connection((url.address, url.port), _Handler, context, **ssl)
def _connect(callback, url, host, address, port, path, is_ssl, method, body, headers, is_json, is_debug, timeout, wrapper, setup, handler, trace, kwargs): c = ConnectContext(callback, url, method, path, host, headers, body, is_json, is_debug, timeout, wrapper, setup, kwargs, trace) return SERVER.add_connection((address, port), ConnectHandler if handler is None else handler, c, ssl=is_ssl)