@@ -152,35 +152,30 @@ def execute_task(task, headers, args):
152152 update_task (args ['task_name' ], TASK_STATES .FAILED )
153153 return
154154
155- # Targets do not get X-Forwarded-Proto from nginx, they use haproxy port.
156- headers ['X-Forwarded-Proto' ] = url .scheme
157- if url .scheme == 'http' :
158- connection = httplib .HTTPConnection (remote_host , url .port )
159- elif url .scheme == 'https' :
160- connection = httplib .HTTPSConnection (remote_host , url .port )
161- else :
162- logger .error ("Task %s tried to use url scheme %s, "
163- "which is not supported." % (
164- args ['task_name' ], url .scheme ))
165-
166- skip_host = False
167- if 'host' in headers or 'Host' in headers :
168- skip_host = True
155+ # Tasks should use HTTP to bypass scheme redirects since they use HAProxy.
156+ connection = httplib .HTTPConnection (remote_host , url .port )
169157
170158 skip_accept_encoding = False
171159 if 'accept-encoding' in headers or 'Accept-Encoding' in headers :
172160 skip_accept_encoding = True
173161
174162 connection .putrequest (method ,
175163 urlpath ,
176- skip_host = skip_host ,
177164 skip_accept_encoding = skip_accept_encoding )
178165
179166 # Update the task headers
180167 headers ['X-AppEngine-TaskRetryCount' ] = str (task .request .retries )
181168 headers ['X-AppEngine-TaskExecutionCount' ] = str (task .request .retries )
182169
183170 for header in headers :
171+ # Avoid changing the host header from the HAProxy location. Though GAE
172+ # supports host-based routing, we need to make some additional changes
173+ # before we can behave in a similar manner. Using the HAProxy location
174+ # for the host header allows the dispatcher to try extracting a port,
175+ # which it uses to set environment variables for the request.
176+ if header == b'Host' :
177+ continue
178+
184179 connection .putheader (header , headers [header ])
185180
186181 if 'content-type' not in headers or 'Content-Type' not in headers :
0 commit comments