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

Why doesn't {proxy+} work as catchall ? #2072

Open
mangled-data opened this issue Sep 9, 2023 · 1 comment
Open

Why doesn't {proxy+} work as catchall ? #2072

mangled-data opened this issue Sep 9, 2023 · 1 comment

Comments

@mangled-data
Copy link

mangled-data commented Sep 9, 2023


app = Chalice(app_name='chalice-proxy-example')

@app.route('/')
def index():
    return {"message": "Welcome to the root endpoint!"}

@app.route('/resource/{proxy+}', methods=['GET', 'POST'])
def resource_proxy(proxy):
    # proxy contains the path information. 
    # For instance, if you access /resource/a/b/c, proxy will be "a/b/c"
    return {
        "message": "You've accessed the proxy endpoint.",
        "path": proxy
    }


I have tried all combinations and I can't figure out why a generic catch all work. I probably miss something super basic, but at a point where I may have to move to something else. This is such a super great framework, if I could get a reverse proxy type setup working! Can anyone help please ?

$ curl http://127.0.0.1:8000/
{"message":"Welcome to the root endpoint!"}

$ curl http://127.0.0.1:8000/1
{"message": "Missing Authentication Token"}

On chalice, I see 127.0.0.1 - - [09/Sep/2023 15:02:09] "GET /1 HTTP/1.1" 403 -
@pkit
Copy link

pkit commented Sep 15, 2023

It happens because here

chalice/chalice/app.py

Lines 1832 to 1839 in 79838b0

def _main_rest_api_handler(self, event: Any, context: Any) -> Response:
resource_path = event.get('requestContext', {}).get('resourcePath')
if resource_path is None:
return error_response(error_code='InternalServerError',
message='Unknown request.',
http_status_code=500)
http_method = event['requestContext']['httpMethod']
if http_method not in self.routes[resource_path]:

resource_path is ..../{proxy*} and not .../{proxy+} which fails to get the key from dict...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants