| 63 | |
| 64 | |
| 65 | class HTTPRequest(): |
| 66 | def __init__(self, cookies=None, options=None): |
| 67 | self.c = pycurl.Curl() |
| 68 | self.rep = None |
| 69 | |
| 70 | self.cj = cookies #cookiejar |
| 71 | |
| 72 | self.lastURL = None |
| 73 | self.lastEffectiveURL = None |
| 74 | self.abort = False |
| 75 | self.code = 0 # last http code |
| 76 | |
| 77 | self.header = "" |
| 78 | |
| 79 | self.headers = [] #temporary request header |
| 80 | |
| 81 | self.initHandle() |
| 82 | self.setInterface(options) |
| 83 | |
| 84 | self.c.setopt(pycurl.WRITEFUNCTION, self.write) |
| 85 | self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader) |
| 86 | |
| 87 | self.log = getLogger("log") |
| 88 | |
| 89 | |
| 90 | def initHandle(self): |
| 91 | """ sets common options to curl handle """ |
| 92 | self.c.setopt(pycurl.FOLLOWLOCATION, 1) |
| 93 | self.c.setopt(pycurl.MAXREDIRS, 5) |
| 94 | self.c.setopt(pycurl.CONNECTTIMEOUT, 30) |
| 95 | self.c.setopt(pycurl.NOSIGNAL, 1) |
| 96 | self.c.setopt(pycurl.NOPROGRESS, 1) |
| 97 | if hasattr(pycurl, "AUTOREFERER"): |
| 98 | self.c.setopt(pycurl.AUTOREFERER, 1) |
| 99 | self.c.setopt(pycurl.SSL_VERIFYPEER, 0) |
| 100 | self.c.setopt(pycurl.LOW_SPEED_TIME, 30) |
| 101 | self.c.setopt(pycurl.LOW_SPEED_LIMIT, 5) |
| 102 | |
| 103 | #self.c.setopt(pycurl.VERBOSE, 1) |
| 104 | |
| 105 | self.c.setopt(pycurl.USERAGENT, |
| 106 | "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0") |
| 107 | if pycurl.version_info()[7]: |
| 108 | self.c.setopt(pycurl.ENCODING, "gzip, deflate") |
| 109 | self.c.setopt(pycurl.HTTPHEADER, ["Accept: */*", |
| 110 | "Accept-Language: en-US,en", |
| 111 | "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", |
| 112 | "Connection: keep-alive", |
| 113 | "Keep-Alive: 300", |
| 114 | "Expect:"]) |
| 115 | |
| 116 | def setInterface(self, options): |
| 117 | |
| 118 | interface, proxy, ipv6 = options["interface"], options["proxies"], options["ipv6"] |
| 119 | |
| 120 | if interface and interface.lower() != "none": |
| 121 | self.c.setopt(pycurl.INTERFACE, str(interface)) |
| 122 |
no outgoing calls
no test coverage detected