Samesite - proxy that can cache partial transfers

Diff
anonymous

Diff

Differences From Artifact [83281b8c59]:

To Artifact [c17785c61d]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3.2

from __future__ import unicode_literals, print_function

#import gevent.monkey
#gevent.monkey.patch_all()

import argparse, os
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', dest = 'config', help = 'config file location', metavar = 'FILE', default = 'samesite.conf')
args = parser.parse_args()
assert os.access(args.config, os.R_OK), "Fatal error: can't read {}".format(args.config)

import configparser


<
<
<
<
<







1
2





3
4
5
6
7
8
9
#!/usr/bin/env python3.2






import argparse, os
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', dest = 'config', help = 'config file location', metavar = 'FILE', default = 'samesite.conf')
args = parser.parse_args()
assert os.access(args.config, os.R_OK), "Fatal error: can't read {}".format(args.config)

import configparser
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
			thisDir = re.compile('^(.*)/$').match(config[section]['dir'])
			if thisDir:
				config[section]['dir'] = thisDir.group(1)
			if not re.compile('^/(.*)$').match(config[section]['dir']):
				config[section]['dir'] = cache_dir + os.sep + config[section]['dir']
		else:
			config[section]['dir'] = cache_dir + os.sep + section

		if not 'root' in config[section]:
			config[section]['root'] = section

#assert options.port or os.access(options.log, os.R_OK), 'Log file unreadable'

const_desc_fields = set(['Content-Length', 'Last-Modified', 'Pragma'])
const_ignore_fields = set([







<







29
30
31
32
33
34
35

36
37
38
39
40
41
42
			thisDir = re.compile('^(.*)/$').match(config[section]['dir'])
			if thisDir:
				config[section]['dir'] = thisDir.group(1)
			if not re.compile('^/(.*)$').match(config[section]['dir']):
				config[section]['dir'] = cache_dir + os.sep + config[section]['dir']
		else:
			config[section]['dir'] = cache_dir + os.sep + section

		if not 'root' in config[section]:
			config[section]['root'] = section

#assert options.port or os.access(options.log, os.R_OK), 'Log file unreadable'

const_desc_fields = set(['Content-Length', 'Last-Modified', 'Pragma'])
const_ignore_fields = set([
75
76
77
78
79
80
81




82
83
84
85
86
87
88

		myPath = re.compile('^(.*?)(\?.*)$').match(self.path)
		if myPath:
			my_path = myPath.group(1)
		else:
			my_path = self.path





		config_host = config[self.headers['Host']]

		if config_host['sub'] != None and config_host['strip'] != None and len(config_host['strip']) > 0:
			string = re.compile(config_host['strip']).sub(config_host['sub'], my_path)
			my_path = string

		my_path_b = my_path.encode('utf-8')







>
>
>
>







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

		myPath = re.compile('^(.*?)(\?.*)$').match(self.path)
		if myPath:
			my_path = myPath.group(1)
		else:
			my_path = self.path

		if not config.has_section(self.headers['Host']):
			config.add_section(self.headers['Host'])
			config[self.headers['Host']]['root'] = self.headers['Host']
			config[self.headers['Host']]['dir'] = cache_dir + os.sep + self.headers['Host']
		config_host = config[self.headers['Host']]

		if config_host['sub'] != None and config_host['strip'] != None and len(config_host['strip']) > 0:
			string = re.compile(config_host['strip']).sub(config_host['sub'], my_path)
			my_path = string

		my_path_b = my_path.encode('utf-8')