Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace view reverse URLs with header value #14934

Closed

Conversation

fosterseth
Copy link
Member

@fosterseth fosterseth commented Feb 28, 2024

SUMMARY

Enables replacing part of the URLs that appear on the API page with a request header.

If a special header is present in the HTTP request, the substring will be replaced with the header value provided.

for example,

in settings.py

URL_REPLACE_FROM_HEADER = {
    'header': 'Aap-Prefix',
    'to_replace': 'api/v2',
}

This will replace

api/v2/instances/3

with

api/controller/v2/instances/3

if 'Aap-Prefix' is defined in the request header.

This feature is added to allow consistent URLs when controller is deployed alongside aap-gateway.

  • should the setting be turned off be default
  • there are few places where we import reverse from restframework and django.urls instead of our custom defined reverse. So we may need to tweak those imports
ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • API

Enables replacing part of the URLs that
appear on the API page with a request header.

If a special header is present in the HTTP request,
the substring will be replaced with the header value
provided.

for example,

in settings.py

URL_REPLACE_FROM_HEADER = {
    'header': 'Aap-Prefix',
    'to_replace': 'api/v2',
}

will replace occurrences of

    api/v2/instances/3

with

    api/controller/v2/instances/3

if 'Aap-Prefix' is defined in the request header.

This feature is added to allow consistent URLs when
controller is deployed alongside aap-gateway.

Signed-off-by: Seth Foster <[email protected]>
@fosterseth fosterseth changed the title Replace view reverse URLs with header Replace view reverse URLs with header value Feb 28, 2024
@fosterseth
Copy link
Member Author

fosterseth commented Feb 28, 2024

note: hyperlinking only works after disabling the path_rewrite_filter in the http filters on aap-gateway.

@@ -165,6 +165,11 @@
# reverse proxy.
REMOTE_HOST_HEADERS = ['REMOTE_ADDR', 'REMOTE_HOST']

URL_REPLACE_FROM_HEADER = {
'header': 'Aap-Prefix', # e.g. api/controller/v2
'to_replace': 'api/v2', # the header string will replace this substring in the URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a great thing to test using override_settings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wait, we don't care about different setting values. We want to test different headers. Not sure if this is doable in unit tests now.

@dmzoneill dmzoneill marked this pull request as draft February 28, 2024 03:52
@fosterseth
Copy link
Member Author

I believe this was solved in another pr

@fosterseth fosterseth closed this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants