Exemple #1
0
    def sendHttpRequest(self,
                        command="POST",
                        url="",
                        header="",
                        body="",
                        bodyArgs="{0},{1}",
                        reqsetting="isRespHeader:true;sslVersion:-1"):
        command = command.upper()
        if bodyArgs != "":
            url = self.__replaceArgStr(url, bodyArgs)
            body = self.__replaceArgStr(body, bodyArgs)
        h = self._toHeaders(header)
        reqsetting = self._toHeaders(reqsetting)

        if command.__contains__("https") or command.__contains__(
                "FORM") or command.__contains__("CURL"):
            command = command.replace("CURL", '')
            resp = self.__curlHttpRequest(
                url, body, command, h,
                tryGet(reqsetting, 'isRespHeader', 'false') == 'true',
                tryGet(reqsetting, 'sslVersion', '-1'))
        else:
            resp = curl(url, body, command=command, logHandler=plog.info, **h)
        try:
            return toJsonObj(resp)
        except:
            return resp
Exemple #2
0
    def httprequest(
            self,
            command="POST",
            url="",
            header="",
            body="",
            bodyArgs="{0},{1}",
            reqsetting="isRespHeader:true;sslVersion:-1;connTimeout:60",
            isjsonresp=True):
        command = command.upper()
        if bodyArgs != "":
            url = self.__replaceArgStr(url, bodyArgs)
            body = self.__replaceArgStr(body, bodyArgs)
        h = self.__toHeaders(header)
        reqsetting = self.__toHeaders(reqsetting)

        if url.startswith("https") or command.__contains__(
                "FORM") or command.__contains__("CURL"):
            if not command.__contains__("CURL"):
                resp = httpscurl(
                    url, body, command, h,
                    tryGet(reqsetting, 'isRespHeader', 'false') == 'true')
            else:
                command = command.replace("CURL", '')
                resp = self.__curlHttpRequest(
                    url, body, command, h,
                    tryGet(reqsetting, 'isRespHeader', 'false') == 'true',
                    tryGet(reqsetting, 'sslVersion', '-1'))
        else:
            resp = curl(url,
                        body,
                        command=command,
                        logHandler=plog.info,
                        connTimeout=int(tryGet(reqsetting, 'connTimeout',
                                               '60')),
                        **h)
        if isjsonresp:
            try:
                return toJsonObj(resp)
            except:
                pass
        return resp
Exemple #3
0
    def __analyzeSession__(self, isMock, command, reqPath, reqParam, respBody,
                           reqTime, respTime, respStatus, reqAddress,
                           reqHeader, respHeader):
        host, ip = reqHeader['host'], reqAddress[0]
        if self.fromIps is not None and self.fromIps.__contains__(ip):
            hostInfo = "%s/%s" % (ip, host)
        elif self.logNameHasOrigin:
            origin = tryGet(reqHeader, "origin", "").replace("http://", "")
            hostInfo = host if origin == "" else ("%s_%s" % (origin, host))
        else:
            hostInfo = host

        isLogResp = self.__isLogResponse__(reqPath, reqParam, respBody)
        reqInfo = self.__getSimpleSession__(isLogResp, isMock, command,
                                            reqPath, reqParam, respBody,
                                            reqTime, respTime, respStatus,
                                            reqAddress, reqHeader, respHeader)
        self.__getHostLog__(hostInfo).info(reqInfo)
Exemple #4
0
 def __getProxyInfo__(self, headers, address, path):
     ip, port, host = "", 80, ""
     if tryGet(headers, "cfrom", None) != self.localHosts:
         try:  # get by host
             ip = headers["host"].lower()
             ps = ip.split(":")
             if len(ps) == 2:
                 ip, port = ps[0], int(ps[1])
             ps = self.hostIp[ip]
             ip, port, host = ps['ip'], ps['port'], ps['host']
         except:  # get by path
             ps = self.__getPathProxy__(path) if self.pathIp else None
             if ps is None:
                 if self.isDebugMode:
                     slog.warn("Not found proxy: %s \t%s" % (ip, path))
             else:
                 ip, port, host = ps['ip'], ps['port'], ps['host']
     if ip == "":
         if self.isDebugMode: slog.error("No proxy hosts: %s" % headers)
         raise ProxyHttpHandle.NoHostException()
     return ip, port, host
Exemple #5
0
 def __getMockResponse__(self, reqPath, reqParam, reqHeader):
     urlmmock = self._getMockkey(reqPath, reqParam)
     return tryGet(urlmmock, 's', 200), tryGet(urlmmock, 'w',
                                               0), urlmmock['d']