rewrite_parse_chunked_req
This commit is contained in:
parent
443f3b6fe3
commit
cdfa5c4191
@ -332,7 +332,7 @@ from notes where %s""" % lim, self.maxUsn)
|
|||||||
self.col.db.executemany(
|
self.col.db.executemany(
|
||||||
"insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)",
|
"insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)",
|
||||||
rows)
|
rows)
|
||||||
self.col.after_note_updates([f[0] for f in rows],True)
|
self.col.after_note_updates([f[0] for f in rows], mark_modified=False, generate_cards=False)
|
||||||
|
|
||||||
# Col config
|
# Col config
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|||||||
@ -410,38 +410,67 @@ class Requests(object):
|
|||||||
length = 0 if content_len == '' else int(content_len)
|
length = 0 if content_len == '' else int(content_len)
|
||||||
body=b''
|
body=b''
|
||||||
d={}
|
d={}
|
||||||
|
|
||||||
if length == 0:
|
if length == 0:
|
||||||
if input is None:
|
if input is None:
|
||||||
return
|
return
|
||||||
if env.get('HTTP_TRANSFER_ENCODING','0') == 'chunked':
|
if env.get('HTTP_TRANSFER_ENCODING','0') == 'chunked':
|
||||||
# readlines and read(no argument) will block
|
# readlines and read(no argument) will block
|
||||||
|
# convert byte str to number base 16
|
||||||
leng=int(input.readline(),16)
|
leng=int(input.readline(),16)
|
||||||
|
c=0
|
||||||
|
bdry=b''
|
||||||
|
data=[]
|
||||||
|
data_other=[]
|
||||||
while leng >0:
|
while leng >0:
|
||||||
body += input.read(leng+2)
|
c+=1
|
||||||
leng = int(input.readline(),16)
|
dt = input.read(leng+2)
|
||||||
boundary=body.splitlines()[0]
|
if c==1:
|
||||||
items=body.split(boundary)
|
bdry=dt
|
||||||
items.pop()
|
elif c>=3:
|
||||||
items.pop(0)
|
# data
|
||||||
# parse data
|
data_other.append(dt)
|
||||||
data_raw=items[0].strip()
|
line=input.readline()
|
||||||
cd=data_raw.splitlines()[0]
|
leng = int(line,16)
|
||||||
data_without_cd=data_raw[len(cd):].strip()
|
print(line)
|
||||||
data=b''
|
data_other=[item for item in data_other if item!=b'\r\n\r\n']
|
||||||
if b'\r\n' in data_without_cd:
|
for item in data_other:
|
||||||
# seems b'\r\n' should not exist in data
|
if bdry in item:
|
||||||
data=re.sub(b'\r\n',b'',data_without_cd,flags=re.M)
|
break
|
||||||
else:
|
data.append(item.strip())
|
||||||
data=data_without_cd
|
d['data']=b''.join(data)
|
||||||
d['data']=data
|
others=data_other[len(data):]
|
||||||
#
|
boundary=others[0]
|
||||||
others=items[1:]
|
others=b''.join(others).split(boundary.strip())
|
||||||
|
others.pop()
|
||||||
|
others.pop(0)
|
||||||
for i in others:
|
for i in others:
|
||||||
i=i.splitlines()
|
i=i.splitlines()
|
||||||
key=re.findall(b'name="(.*?)"',i[2])[0].decode('utf-8')
|
key=re.findall(b'name="(.*?)"',i[2],flags=re.M)[0].decode('utf-8')
|
||||||
v=i[-3].decode('utf-8')
|
v=i[-1].decode('utf-8')
|
||||||
d[key]=v
|
d[key]=v
|
||||||
|
# boundary=body.splitlines()[0]
|
||||||
|
# items=body.split(boundary)
|
||||||
|
# items.pop()
|
||||||
|
# items.pop(0)
|
||||||
|
# # parse data
|
||||||
|
# data_raw=items[0].strip()
|
||||||
|
# cd=data_raw.splitlines()[0]
|
||||||
|
# data_without_cd=data_raw[len(cd):].strip()
|
||||||
|
# data=b''
|
||||||
|
# if b'\r\n' in data_without_cd:
|
||||||
|
# # seems b'\r\n' should not exist in data
|
||||||
|
# data=re.sub(b'\r\n',b'',data_without_cd,flags=re.M)
|
||||||
|
# else:
|
||||||
|
# data=data_without_cd
|
||||||
|
# d['data']=data
|
||||||
|
# #
|
||||||
|
# others=items[1:]
|
||||||
|
# for i in others:
|
||||||
|
# i=i.splitlines()
|
||||||
|
# key=re.findall(b'name="(.*?)"',i[2])[0].decode('utf-8')
|
||||||
|
# v=i[-3].decode('utf-8')
|
||||||
|
# d[key]=v
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -616,6 +645,7 @@ class SyncApp:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = p['data']
|
data = p['data']
|
||||||
|
print(compression)
|
||||||
data = self._decode_data(data, compression)
|
data = self._decode_data(data, compression)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user