Samesite - proxy that can cache partial transfers

Diff
anonymous

Diff

Differences From Artifact [d358a0b198]:

To Artifact [ddef44cfde]:


242
243
244
245
246
247
248

249
250
251
252
253
254





255
256
257
258
259
260
261
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267







+






+
+
+
+
+







						while True:
							range = needed.pop()
							if range[0] == None:
								break
							ranges += '{}-{}'.format(range[0], range[1] - 1),
						my_headers['range'] = 'bytes=' + ','.join(ranges)

				headers['Accept-Encoding'] = 'gzip'
				request = urllib2.Request(request, headers = my_headers)

				source = urllib2.urlopen(request)
				new_record = {}
				new_record['_parts'] = record['_parts']
				headers = source.info()

				if 'content-encoding' in headers and headers['content-encoding'] == 'gzip':
					import gzip, StringIO
					buf = StringIO.StringIO(source.read())
					source = gzip.GzipFile(fileobj=buf)

				# stripping unneeded headers (XXX make this inplace?)
				for header in headers:
					if header in desc_fields:
						#if header == 'Pragma' and headers[header] != 'no-cache':
						if header == 'content-length':
							if 'content-range' not in headers:
325
326
327
328
329
330
331

332
333
334
335
336
337
338
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345







+







							pass
						os.renames(empty_name, temp_name)
					temp_file = open(temp_name, 'r+b')
					if requested_ranges == None and needed == None:
						needed = new_record['_parts']
					needed.rewind()
					while True:
						# XXX can make this implicit - one request per range
						(start, end) = needed.pop()
						if start == None:
							break
						stream_last = start
						old_record = copy.copy(new_record)
						if end - start < block_size:
							req_block_size = end - start