Index: trunk/extensions/SwiftMedia/wmf/rewrite.py |
— | — | @@ -104,6 +104,7 @@ |
105 | 105 | self.key = conf['key'].strip() |
106 | 106 | self.thumbhost = conf['thumbhost'].strip() |
107 | 107 | self.writethumb = 'writethumb' in conf |
| 108 | + self.user_agent = conf['user_agent'].strip() |
108 | 109 | self.bind_port = conf['bind_port'].strip() |
109 | 110 | self.shard_containers = conf['shard_containers'].strip() #all, some, none |
110 | 111 | if (self.shard_containers == 'some'): |
— | — | @@ -127,9 +128,14 @@ |
128 | 129 | # using urllib2.url() |
129 | 130 | opener = urllib2.build_opener() |
130 | 131 | # Pass on certain headers from the caller squid to the scalers |
131 | | - for header_to_pass in ['X-Forwarded-For', 'X-Original-URI', 'User-Agent']: |
| 132 | + opener.addheaders = [] |
| 133 | + if reqorig.headers.get('User-Agent') != None: |
| 134 | + opener.addheaders.append(('User-Agent', reqorig.headers.get('User-Agent'))) |
| 135 | + else: |
| 136 | + opener.addheaders.append(('User-Agent', self.user_agent)) |
| 137 | + for header_to_pass in ['X-Forwarded-For', 'X-Original-URI']: |
132 | 138 | if reqorig.headers.get( header_to_pass ) != None: |
133 | | - opener.addheaders[header_to_pass] = reqorig.headers.get( header_to_pass ) |
| 139 | + opener.addheaders.append((header_to_pass, reqorig.headers.get( header_to_pass ))) |
134 | 140 | # At least in theory, we shouldn't be handing out links to originals |
135 | 141 | # that we don't have (or in the case of thumbs, can't generate). |
136 | 142 | # However, someone may have a formerly valid link to a file, so we |