示例#1
0
	def continue_request (self, request, collector, asyncon = None):
		if request.command != "connect" and self.has_valid_cache (request, collector is not None):
			return
		
		if asyncon is None:		
			if request.command == "connect":
				asyncon_key = "tunnel://" + request.uri + "/"
				keep_alive = PROXY_TUNNEL_KEEP_ALIVE
			else:
				asyncon_key = request.uri					
				keep_alive = PROXY_KEEP_ALIVE
			asyncon = self.clusters ["__socketpool__"].get (asyncon_key)				
			asyncon.set_keep_alive (keep_alive)
			request.channel.set_socket_timeout (keep_alive)
			if request.command == "connect":
				# refix zombie_timeout becasue it will be not recalcuated
				asyncon.set_timeout (keep_alive)
				
		try:				
			req = http_request.HTTPRequest (request.uri, request.command, collector is not None, logger = self.wasc.logger.get ("server"))				
			r = proxy_request_handler (asyncon, req, self.callback, request, collector)			
			if collector:
				collector.asyncon = asyncon
			r.handle_request ()
				
		except:
			asyncon.set_active (False)
			self.wasc.logger.trace ("server")			
			request.response.error (500, "Proxy Failed")
示例#2
0
    def route(self, request, collector):
        current_cluster, route_len = self.find_cluster(request)
        psysicaluri = request.uri[route_len:]
        if psysicaluri == "": psysicaluri = "/"
        elif psysicaluri[0] != "/": psysicaluri = "/" + psysicaluri

        request.loadbalance_retry += 1
        retry = request.loadbalance_retry
        asyncon = current_cluster.get(index=-1)

        if not asyncon:
            request.logger(
                "nopool-%d, url: %s, cluster index: %d" %
                (retry, request.uri, route), 'warn')
            return request.response.error(503)

        if retry > 1:
            request.logger(
                "failsafe-%d, target: %s:%s, url: %s, cluster index: %d" %
                (retry, asyncon.address[0], asyncon.address[1], request.uri,
                 route), 'warn')

        fetcher = http_request.HTTPRequest(
            psysicaluri,
            request.command,
            collector is not None,
            logger=self.wasc.logger.get("server"))
        r = proxy_handler.proxy_request_handler(asyncon, fetcher,
                                                self.callback, request,
                                                collector)
        r.handle_request()
示例#3
0
    def make_request(self,
                     method,
                     uri,
                     data,
                     headers,
                     auth=None,
                     meta={},
                     version="1.1"):
        method = method.upper()
        if isinstance(headers, dict):
            headers = [(k, v) for k, v in headers.items()]
        headers = self.override(headers)
        if method == "UPLOAD":
            r = request.HTTPMultipartRequest(uri, "POST", data, headers, auth,
                                             None, meta, version)
        else:
            r = request.HTTPRequest(uri, method, data, headers, auth, None,
                                    meta, version)

        hr = self.__generate(r)
        if data:
            payload = r.get_payload()
            if method == "UPLOAD":
                payload = self.__serialize(payload)
            hr.set_body(payload)
        return hr
示例#4
0
    def _build_request(self, method, params):
        self._cached_request_args = (method, params)  # backup for retry
        if self._use_cache and rcache.the_rcache:
            self._cached_result = rcache.the_rcache.get(
                self._get_ident(), self._use_cache)
            if self._cached_result is not None:
                self._cached_result.meta = self._meta
                self._callback and tuple_cb(self._cached_result,
                                            self._callback)
                return
            else:
                self._use_cache = False

        requests = 0
        while self._avails():
            if self._cluster.get_name() != "__socketpool__":
                asyncon = self._get_connection(None)
            else:
                asyncon = self._get_connection(self._uri)

            self._auth = self._auth or asyncon.get_auth()
            _reqtype = self._reqtype.lower()
            rs = Dispatcher(self._cv,
                            asyncon.address,
                            ident=not self._mapreduce and self._get_ident()
                            or None,
                            filterfunc=self._filter,
                            cachefs=self._cachefs,
                            callback=self._collect)
            self._requests[rs] = asyncon
            args = (params, self._headers, self._auth, self._logger,
                    self._meta)
            try:
                if _reqtype in ("ws", "wss"):
                    handler = ws_request_handler.RequestHandler
                    request = ws_request.Request(self._uri, *args)
                else:
                    if not self._use_cache:
                        self._add_header("Cache-Control", "no-cache")
                    handler = http_request_handler.RequestHandler
                    try:
                        class_ = self.proto_map[_reqtype]
                    except KeyError:
                        if _reqtype == "upload":
                            request = http_request.HTTPMultipartRequest(
                                self._uri, _reqtype, *args)
                        else:
                            request = http_request.HTTPRequest(
                                self._uri, _reqtype, *args)
                    else:
                        request = class_(self._uri, method, *args)
                requests += self._handle_request(request, rs, asyncon, handler)

            except:
                self._logger("Request Creating Failed", "fail")
                self._logger.trace()
                rs.request_failed()
                asyncon.set_active(False)
                continue

        if requests:
            self._request = request  # sample for unitest
            trigger.wakeup()

        if _reqtype[-3:] == "rpc":
            return self