S-mishina / flexiblemockserver

This is a mock server used to verify the operation of service mesh tools. Service mesh tools refer to Istio, Linkerd, and Kuma.
0 stars 0 forks source link

Refactor main.py for Better Error Handling and Application Startup #20

Closed S-mishina closed 3 months ago

S-mishina commented 3 months ago

sample

@app.route('/status/<int:status_code>', methods=HTTP_METHODS)
def only_status_code(status_code, sleep_time=0):
@app.route('/status/<int:status_code>', methods=HTTP_METHODS)
@app.route('/status/<int:status_code>/', methods=HTTP_METHODS)
def only_status_code(status_code, sleep_time=0):

summary

In the code before the change, matching occurs only when there is no trailing slash (/) in the URL. That is, /status/200/ will match, but /status/200/ will not.

In Flask routing, trailing slashes have a special meaning. If a trailing slash is present, accesses to URLs without that slash are automatically redirected to URLs with the slash. Conversely, if there is no trailing slash, access to a URL with a trailing slash will return a 308 error.

Thus, this change is intended to allow access to URLs with trailing slashes (such as /status/200/), thereby ensuring that the same view is used whether the URL has a trailing slash or not. This allows for normal operation even if the user forgets to add a trailing slash.