mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
fix
This commit is contained in:
parent
61382d5937
commit
d7ebef036a
@ -49,15 +49,22 @@ class Session(Sessionbase):
|
|||||||
def _getmembyte(self,mem):
|
def _getmembyte(self,mem):
|
||||||
return cast(mem.memory,POINTER(c_char))[:mem.size]
|
return cast(mem.memory,POINTER(c_char))[:mem.size]
|
||||||
def request_impl(self,
|
def request_impl(self,
|
||||||
method,scheme,server,port,param,url,headers,dataptr,datalen,proxy,stream,verify ):
|
method,scheme,server,port,param,url,headers,cookies,dataptr,datalen,proxy,stream,verify):
|
||||||
|
|
||||||
|
headers=self._parseheader(headers,None)#curl对于headers中有cookie且session中也有cookie的情况下,不会自动合并而是会有两个cookie键,所以不能在header里放cookie
|
||||||
if self._status==0:
|
if self._status==0:
|
||||||
curl=self.curl
|
curl=self.curl
|
||||||
__=autostatus(self)
|
__=autostatus(self)
|
||||||
else:
|
else:
|
||||||
#不能多线程同时复用同一个curl对象
|
#不能多线程同时复用同一个curl对象
|
||||||
curl=AutoCURLHandle(curl_easy_duphandle(self.curl))
|
curl=AutoCURLHandle(curl_easy_duphandle(self.curl))
|
||||||
|
if cookies:
|
||||||
|
cookies.update(self.cookies)
|
||||||
|
else:
|
||||||
|
cookies=self.cookies
|
||||||
|
if cookies:
|
||||||
|
cookie=self._parsecookie(cookies)
|
||||||
|
curl_easy_setopt(curl, CURLoption.CURLOPT_COOKIE, cookie.encode('utf8'));
|
||||||
curl_easy_setopt(curl,CURLoption.CURLOPT_CUSTOMREQUEST,method.upper().encode('utf8'))
|
curl_easy_setopt(curl,CURLoption.CURLOPT_CUSTOMREQUEST,method.upper().encode('utf8'))
|
||||||
|
|
||||||
self.last_error=curl_easy_setopt(curl,CURLoption.CURLOPT_URL,url.encode('utf8'))
|
self.last_error=curl_easy_setopt(curl,CURLoption.CURLOPT_URL,url.encode('utf8'))
|
||||||
|
@ -140,16 +140,16 @@ class Sessionbase:
|
|||||||
_x=[]
|
_x=[]
|
||||||
|
|
||||||
if cookies:
|
if cookies:
|
||||||
|
cookie=self._parsecookie(cookies)
|
||||||
self.cookies.update(cookies)
|
headers.update({'Cookie':cookie})
|
||||||
_c=[]
|
|
||||||
for k ,v in self.cookies.items():
|
|
||||||
_c.append('{}={}'.format(k,v))
|
|
||||||
cookie='; '.join(_c)
|
|
||||||
headers.update({'Cookie':cookie})
|
|
||||||
for k in sorted(headers.keys()):
|
for k in sorted(headers.keys()):
|
||||||
_x.append('{}: {}'.format(k,headers[k]))
|
_x.append('{}: {}'.format(k,headers[k]))
|
||||||
return _x
|
return _x
|
||||||
|
def _parsecookie(self,cookie):
|
||||||
|
_c=[]
|
||||||
|
for k ,v in cookie.items():
|
||||||
|
_c.append('{}={}'.format(k,v))
|
||||||
|
return '; '.join(_c)
|
||||||
def _update_header_cookie(self,headerstr):
|
def _update_header_cookie(self,headerstr):
|
||||||
self.headers,cookies=self._parseheader2dict(headerstr)
|
self.headers,cookies=self._parseheader2dict(headerstr)
|
||||||
self.cookies.update(cookies)
|
self.cookies.update(cookies)
|
||||||
@ -162,7 +162,7 @@ class Sessionbase:
|
|||||||
if line[:idx].lower()=='set-cookie':
|
if line[:idx].lower()=='set-cookie':
|
||||||
_c=line[idx+2:].split('; ')[0]
|
_c=line[idx+2:].split('; ')[0]
|
||||||
_idx=_c.find('=')
|
_idx=_c.find('=')
|
||||||
cookie[_c[:_idx]]=_c[idx+1:]
|
cookie[_c[:_idx]]=_c[_idx+1:]
|
||||||
else:
|
else:
|
||||||
header[line[:idx]]=line[idx+2:]
|
header[line[:idx]]=line[idx+2:]
|
||||||
return CaseInsensitiveDict(header),cookie
|
return CaseInsensitiveDict(header),cookie
|
||||||
@ -199,9 +199,9 @@ class Sessionbase:
|
|||||||
|
|
||||||
scheme,server,port,param,url=self._parseurl(url,params)
|
scheme,server,port,param,url=self._parseurl(url,params)
|
||||||
headers,dataptr,datalen=self._parsedata(data,headers,json)
|
headers,dataptr,datalen=self._parsedata(data,headers,json)
|
||||||
headers=self._parseheader(headers,cookies)
|
|
||||||
proxy= proxies.get(scheme,None) if proxies else None
|
proxy= proxies.get(scheme,None) if proxies else None
|
||||||
_= self.request_impl(method,scheme,server,port,param,url,headers,dataptr,datalen,proxy,stream,verify)
|
|
||||||
|
_= self.request_impl(method,scheme,server,port,param,url,headers,cookies,dataptr,datalen,proxy,stream,verify)
|
||||||
|
|
||||||
return _
|
return _
|
||||||
Sessionimpl=[Sessionbase]
|
Sessionimpl=[Sessionbase]
|
||||||
|
@ -39,8 +39,8 @@ class Session(Sessionbase):
|
|||||||
winhttpsetproxy(hsess,proxy)
|
winhttpsetproxy(hsess,proxy)
|
||||||
|
|
||||||
def request_impl(self,
|
def request_impl(self,
|
||||||
method,scheme,server,port,param,url,headers,dataptr,datalen,proxy,stream,verify):
|
method,scheme,server,port,param,url,headers,cookies,dataptr,datalen,proxy,stream,verify):
|
||||||
|
headers=self._parseheader(headers,cookies)
|
||||||
flag=WINHTTP_FLAG_SECURE if scheme=='https' else 0
|
flag=WINHTTP_FLAG_SECURE if scheme=='https' else 0
|
||||||
#print(server,port,param,dataptr)
|
#print(server,port,param,dataptr)
|
||||||
headers='\r\n'.join(headers)
|
headers='\r\n'.join(headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user