aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.61k stars 1.01k forks source link

{proxy+} path glob not working in local chalice server #2118

Open bbuechler opened 1 week ago

bbuechler commented 1 week ago

From what I can tell, at least with chalice 1.31.2, the {proxy+} glob seems to be broken in the local development server, even though it works properly in AWS. When I try to use nested URLs with this code:

from chalice import Chalice

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():
    return {
        "message": "You've accessed the proxy endpoint.",
        "path": app.current_request.uri_params.get("proxy+")
    }

This happens:

curl http://127.0.0.1:8000/resource/good
127.0.0.1 - - [18/Sep/2024 15:34:52] "GET /resource/good HTTP/1.1" 200 -
{"message":"You've accessed the proxy endpoint.","path":"good"}

curl http://127.0.0.1:8000/resource/still_good/            
127.0.0.1 - - [18/Sep/2024 15:36:40] "GET /resource/still_good/ HTTP/1.1" 200 -
{"message":"You've accessed the proxy endpoint.","path":"still_good"}

curl http://127.0.0.1:8000/resource/should_work/but_doesnt
127.0.0.1 - - [18/Sep/2024 15:35:07] "GET /resource/should_work/but_doesnt HTTP/1.1" 403 -
{"message": "Missing Authentication Token"}

curl http://127.0.0.1:8000/resource/should_work/but_doesnt/
127.0.0.1 - - [18/Sep/2024 15:35:10] "GET /resource/should_work/but_doesnt/ HTTP/1.1" 403 -
{"message": "Missing Authentication Token"}

When deployed to AWS, this works perfectly fine. However, in the chalice local server, it won't route.

The weird thing is, I pretty much can't find any documentation for how {proxy+} is supposed to work Chalice. BUT, we have lots of code running the uses it. Is it some weird loophole? The more I try to figure out whats going on, the more lost I get.