File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python2
2
+
3
+ import sys
4
+ from os import unlink
5
+ from os .path import exists
6
+
7
+ HEADERS = ('Content-Disposition' , 'Content-Length' , 'Content-Type' ,
8
+ 'ETag' , 'Last-Modified' )
9
+
10
+ def is_sig_header (header ):
11
+ header = header .lower ()
12
+ for s in HEADERS :
13
+ if header .startswith (s .lower ()):
14
+ return True
15
+
16
+ def do ():
17
+ headers_fn = sys .argv [1 ]
18
+ signature_fn = sys .argv [2 ]
19
+
20
+ # first, get all the headers from the latest request
21
+ with open (headers_fn ) as fd :
22
+ headers = [line .strip () for line in fd .readlines ()]
23
+
24
+ last_index = 0
25
+ for index , header in enumerate (headers ):
26
+ if header .startswith ('HTTP/1.' ):
27
+ last_index = index
28
+ headers = headers [last_index :]
29
+
30
+ # select few headers for the signature
31
+ headers = [header for header in headers if is_sig_header (header )]
32
+ signature = '\n ' .join (headers )
33
+
34
+ # read the original signature
35
+ if exists (signature_fn ):
36
+ with open (signature_fn ) as fd :
37
+ original_signature = fd .read ()
38
+ if original_signature == signature :
39
+ return 0
40
+ unlink (signature_fn )
41
+
42
+ if signature :
43
+ with open (signature_fn , 'w' ) as fd :
44
+ fd .write (signature )
45
+
46
+ try :
47
+ ret = do ()
48
+ except :
49
+ ret = 1
50
+
51
+ sys .exit (ret )
52
+
You can’t perform that action at this time.
0 commit comments