Injects cookies, into requests call over route
    :return: route
504142
def play_auth(f):
    

    def wrapper(*args, **kwargs):
        self = args[0]
        if 'cookies' in kwargs:
            raise AttributeError("don't set cookies explicitly")
        if 'auth' in kwargs:
            raise AttributeError("don't set auth token explicitly")

        assert self.is_connected, "not connected, call router.connect(email, password) first"

        if self._jwt_auth:
            kwargs['auth'] = self._jwt_auth
            kwargs['cookies'] = None
        elif self._cookies:
            kwargs['cookies'] = self._cookies
            kwargs['auth'] = None
        else:
            assert False, "no cookies, no JWT, but connected o_O"

        return f(*args, **kwargs)

    return wrapper
574257
def response_cookies(self):
        
        try:
            ret = {}
            for cookie_base_uris in self.response.cookies._cookies.values():
                for cookies in cookie_base_uris.values():
                    for cookie in cookies.keys():
                        ret[cookie] = cookies[cookie].value
            return ret
        except Exception as e:
            self.error = ApiError(
                "Exception in making Request with:: %s\n%s" % (
                    e_, traceback.format_exc()))
            raise Exception(self.error)
910244
def _set_cookies(self, cookies):
        
        cookie_dict = helpers.parse_cookies_str(cookies)
        self.s.cookies.update(cookie_dict)
1097568
def page(self, method, uri, params=None, data=None, headers=None, auth=None, timeout=None,
             allow_redirects=False):
        
        return self.request(
            method,
            uri,
            params=params,
            data=data,
            headers=headers,
            auth=auth,
            timeout=timeout,
            allow_redirects=allow_redirects,
        )
1286048
def route_for(path, env = {}, &block)
      request = fake_request(env_for(path, env))
      yield request if block_given?
      Merb::Router.route_for(request)
    end
1254611
def COOKIES(self):
        
        raw_dict = SimpleCookie(self.headers.get('Cookie',''))
        cookies = {}
        for cookie in six.itervalues(raw_dict):
            cookies[cookie.key] = cookie.value
        return cookies
312319
def request(self, method, path,
                params=None, headers=None, cookies=None, data=None, json=None, allow_redirects=None, timeout=None):
        
        headers = headers or {}
        timeout = timeout if timeout is not None else self._timeout
        allow_redirects = allow_redirects if allow_redirects is not None else self._allow_redirects

        if self._keep_alive and self.__session is None:
            self.__session = requests.Session()

        if self.__session is not None and not self._use_cookies:
            self.__session.cookies.clear()

        address = self._bake_address(path)
        req_headers = copy.deepcopy(self._additional_headers)
        req_headers.update(headers)

        response = http.request(method, address, session=self.__session,
                                params=params, headers=headers, cookies=cookies, data=data, json=json,
                                allow_redirects=allow_redirects, timeout=timeout)
        if self._auto_assert_ok:
            response.assert_ok()
        return response
770753
def route_request(self, request_json, metadata=None):

        '''  '''
        request = Request(request_json)
        request.metadata = metadata
        # add reprompt handler or some such for default?
        handler_fn = self._handlers[self._default] # Set default handling for noisy requests

        if not request.is_intent() and (request.request_type() in self._handlers):
            '''  Route request to a non intent handler '''
            handler_fn = self._handlers[request.request_type()]

        elif request.is_intent() and request.intent_name() in self._handlers['IntentRequest']:
            ''' Route to right intent handler '''
            handler_fn = self._handlers['IntentRequest'][request.intent_name()]

        response = handler_fn(request)
        response.set_session(request.session)
        return response.to_json()
74808
def route(self, uri, methods=frozenset({'GET'}), host=None,
              strict_slashes=False, stream=False, websocket=False):
        '''
        '''

        # Fix case where the user did not prefix the URL with a /
        # and will probably get confused as to why it's not working
        if not uri.startswith('/'):
            uri = '/' + uri

        def response(handler):
            if websocket:
                handler.is_websocket = True
            elif stream:
                handler.is_stream = True
            self.router.add(uri=uri, methods=methods, handler=handler,
                            host=host, strict_slashes=strict_slashes)
            return handler

        return response
279437
def extract_cookies(self, response, request):
        """"""
        _debug("extract_cookies: %s", response.info())
        self._cookies_lock.acquire()
        try:
            self._policy._now = self._now = int(time.time())

            for cookie in self.make_cookies(response, request):
                if self._policy.set_ok(cookie, request):
                    _debug(" setting cookie: %s", cookie)
                    self.set_cookie(cookie)
        finally:
            self._cookies_lock.release()
1243603
def _force_https(self):
        

        if self.session_cookie_secure:
            if not self.app.debug:
                self.app.config['SESSION_COOKIE_SECURE'] = True

        criteria = [
            self.app.debug,
            flask.request.is_secure,
            flask.request.headers.get('X-Forwarded-Proto', 'http') == 'https',
        ]

        local_options = self._get_local_options()

        if local_options['force_https'] and not any(criteria):
            if flask.request.url.startswith('http://'):
                url = flask.request.url.replace('http://', 'https://', 1)
                code = 302
                if self.force_https_permanent:
                    code = 301
                r = flask.redirect(url, code=code)
                return r
337830
def cookie_get(self, name):
		
		if not hasattr(self, 'cookies'):
			return None
		if self.cookies.get(name):
			return self.cookies.get(name).value
		return None
637950
def COOKIES(self):
        
        if self._COOKIES is None:
            raw_dict = SimpleCookie(self.environ.get('HTTP_COOKIE',''))
            self._COOKIES = {}
            for cookie in raw_dict.itervalues():
                self._COOKIES[cookie.key] = cookie.value
        return self._COOKIES
1113819
def middleware(func):
    
    @wraps(func)
    def parse(*args, **kwargs):
        """ get middleware from route, execute middleware in order """
        middleware = copy.deepcopy(kwargs['middleware'])
        kwargs.pop('middleware')
        if request.method == "OPTIONS":
            # return 200 json response for CORS
            return JsonResponse(200)
        if middleware is None:
            return func(*args, **kwargs)
        for mware in middleware:
            ware = mware()
            if ware.status is False:
                return ware.response
            return func(*args, **kwargs)
    return parse
643861
def request(self, method, url, **kwargs):
        
        resp = super(CookieSession, self).request(method, url, **kwargs)

        if not self._auto_renew:
            return resp

        is_expired = any((
            resp.status_code == 403 and
            response_to_json_dict(resp).get('error') == 'credentials_expired',
            resp.status_code == 401
        ))

        if is_expired:
            self.login()
            resp = super(CookieSession, self).request(method, url, **kwargs)

        return resp
980489
def request(self, *args, **kwargs):
        """"""
        headers = self.headers.copy()
        if self.cookiestring:
            headers['Cookie'] = self.cookiestring
        headers.update(kwargs.get('headers', {}))
        kwargs['headers'] = headers

        r = request(*args, **kwargs)
        self.cookies.update(r.cookies)

        return r
142852
def _polling_cookie(self):
        
        parsed_url = urlparse(self._response.request.url)
        host = parsed_url.hostname.strip('.')
        if host == 'localhost':
            return {'cookie': self._response.headers.get('set-cookie', '')}
        return {}