Skip to content

Commit

Permalink
Merge pull request AppScale#3183 from whoarethebritons/task-redirect-…
Browse files Browse the repository at this point in the history
…scheme

Tasks should use http to avoid scheme redirects since they use HAProxy
  • Loading branch information
sjones4 authored Oct 15, 2019
2 parents 29d34f9 + a11dc63 commit be17e5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AppServer/google/appengine/tools/devappserver2/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _handle_request_impl(self, environ, start_response, inst=None,
try:
environ['SERVER_PORT'] = environ['HTTP_HOST'].split(':')[1]
except IndexError:
scheme = environ['HTTP_X_FORWARDED_PROTO']
scheme = environ.get('HTTP_X_FORWARDED_PROTO', 'http')
if scheme == 'http':
environ['SERVER_PORT'] = 80
else:
Expand Down
25 changes: 10 additions & 15 deletions AppTaskQueue/appscale/taskqueue/push_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,35 +154,30 @@ def execute_task(task, headers, args):
update_task(task_name, TASK_STATES.FAILED)
return

# Targets do not get X-Forwarded-Proto from nginx, they use haproxy port.
headers['X-Forwarded-Proto'] = url.scheme
if url.scheme == 'http':
connection = httplib.HTTPConnection(remote_host, url.port)
elif url.scheme == 'https':
connection = httplib.HTTPSConnection(remote_host, url.port)
else:
logger.error("Task %s tried to use url scheme %s, "
"which is not supported." % (
args['task_name'], url.scheme))

skip_host = False
if b'host' in headers or b'Host' in headers:
skip_host = True
# Tasks should use HTTP to bypass scheme redirects since they use HAProxy.
connection = httplib.HTTPConnection(remote_host, url.port)

skip_accept_encoding = False
if 'accept-encoding' in headers or 'Accept-Encoding' in headers:
skip_accept_encoding = True

connection.putrequest(method,
urlpath,
skip_host=skip_host,
skip_accept_encoding=skip_accept_encoding)

# Update the task headers
headers['X-AppEngine-TaskRetryCount'] = str(task.request.retries)
headers['X-AppEngine-TaskExecutionCount'] = str(task.request.retries)

for header in headers:
# Avoid changing the host header from the HAProxy location. Though GAE
# supports host-based routing, we need to make some additional changes
# before we can behave in a similar manner. Using the HAProxy location
# for the host header allows the dispatcher to try extracting a port,
# which it uses to set environment variables for the request.
if header == b'Host':
continue

connection.putheader(header, headers[header])

if 'content-type' not in headers or 'Content-Type' not in headers:
Expand Down

0 comments on commit be17e5f

Please sign in to comment.