Skip to content

Commit

Permalink
Ensure the lang-fixup redirects set a Vary header for Accept-Language (
Browse files Browse the repository at this point in the history
…#14500)

* Ensure the lang-fixup redirects set a Vary header for Accept-Language

Previously, we relied on similar code deep in lib.l10n_utils.render,
but BedrockLangFixupMiddleware runs way before then, so we need(ed)
to add the Vary header here, too.

The orginal code in l10n_utils.render still has value, because it
handles the fallback for a missing/unactive language to en-US

* Ensure the GHA has a unique name for each set of artifacts it may need to upload, dealing with a breaking change in actions/upload-artifact
  • Loading branch information
stevejalim committed Apr 25, 2024
1 parent 04576bf commit 2e45715
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cdn_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ jobs:
matrix:
include:
- LABEL: "General CDN Tests"
SHARD_LABEL: "general-cdn-tests"
MARK_EXPRESSION: "cdn and not cdnprod"
- LABEL: "Prod-only CDN Tests"
SHARD_LABEL: "prod-only-cdn-tests"
MARK_EXPRESSION: cdnprod
env:
BASE_URL: ${{ github.event.inputs.mozorg_service_hostname || 'https://www.mozilla.org' }} # Mozorg base URL
Expand Down Expand Up @@ -77,7 +79,7 @@ jobs:
- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: test-results
name: test-results-${{github.run_id}}-${{ matrix.SHARD_LABEL }}
path: results-${{github.run_id}}
if-no-files-found: ignore # this avoids a false "Warning" if there were no issues

Expand Down
4 changes: 3 additions & 1 deletion bedrock/base/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def _redirect(self, request, lang_code, subpath):
if request.GET:
dest += f"?{request.GET.urlencode()}"

return HttpResponseRedirect(dest)
response = HttpResponseRedirect(dest)
response["Vary"] = "Accept-Language"
return response

def process_request(self, request):
# Initially see if we can separate a lang code from the rest of the URL
Expand Down
1 change: 1 addition & 0 deletions bedrock/base/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_BedrockLangCodeFixupMiddleware(
if resp:
assert resp.status_code == 302
assert resp.headers["location"] == expected_dest
assert resp.headers["vary"].lower() == "accept-language"
else:
# the request will have been annotated by the middleware
assert request.locale == expected_request_locale
Expand Down

0 comments on commit 2e45715

Please sign in to comment.