-
Notifications
You must be signed in to change notification settings - Fork 0
/
external_headers.py
57 lines (41 loc) · 1.41 KB
/
external_headers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# To you Alone, oh God. I commit myself
class PHPHeader():
def __init__(self):
super.__self__
self.header = {}
self.setcookiesheader = []
self.status_str = ""
def computeHeader(self, headers):
# break on (\\r\\n) or (\r\n)
splits = headers.split('\r\n')
# check if splits was successful
if len(splits) > 1:
pass
# else split again
else:
splits = headers.split('\\r\\n')
# clean it up now
for header in splits:
if header.startswith("Set-Cookie"):
# Add cookies from PHP
self._add_send_cookie(header)
continue
elif header.startswith("Status"):
# Add the status code from PHP
self._add_to_status(header)
continue
each_splits = header.split(': ')
item = each_splits[0]
value = each_splits[1]
self.header[item] = value
if 'Content-Disposition' in self.header:
#self.header['Transfer-Encoding'] = 'chunked'
self.header['Keep-Alive'] = 'timeout=5, max=100'
return self.header
def _add_send_cookie(self, line):
self.setcookiesheader.append(line)
return
def _add_to_status(self, line):
self.status_str = line.replace('Status: ', '')
return