Skip to content

Commit

Permalink
Use HAProxy location for the host header
Browse files Browse the repository at this point in the history
Since the host header defines which service the push task goes to
in App Engine, this roughly preserves the same behavior (since the
target service has already been selected at this point). There are
some edge cases (especially during service relocation) where this
behaves differently, but the routing pieces need more work to
support those differences.
  • Loading branch information
cdonati committed Oct 14, 2019
1 parent cd8c4be commit 8916362
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions AppTaskQueue/appscale/taskqueue/push_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,27 @@ def execute_task(task, headers, args):
# Tasks should use HTTP to bypass scheme redirects since they use HAProxy.
connection = httplib.HTTPConnection(remote_host, url.port)

skip_host = False
if b'host' in headers or b'Host' in headers:
skip_host = True

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 8916362

Please sign in to comment.