mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-28 22:44:24 +01:00
Improvements for --base-path usage (#292)
* Trim trailing slashes in --base-path option * Redirect `/base-path` to `/base-path/` * Log endpoints if --base-path is provided * Use predefined token for standard header 'location'
This commit is contained in:
committed by
GitHub
parent
ea27950594
commit
398bebf091
15
src/http.c
15
src/http.c
@@ -160,6 +160,21 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
||||
break;
|
||||
}
|
||||
|
||||
// accessing `/base-path` redirects to `/base-path/`
|
||||
if (strcmp(pss->path, endpoints.parent) == 0) {
|
||||
if (lws_add_http_header_status(wsi, HTTP_STATUS_FOUND, &p, end)
|
||||
|| lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_LOCATION,
|
||||
endpoints.index,
|
||||
strlen(endpoints.index), &p, end)
|
||||
|| lws_add_http_header_content_length(wsi, 0, &p, end)
|
||||
|| lws_finalize_http_header(wsi, &p, end)
|
||||
|| lws_write(wsi, buffer + LWS_PRE, p - (buffer + LWS_PRE),
|
||||
LWS_WRITE_HTTP_HEADERS) < 0
|
||||
)
|
||||
return 1;
|
||||
goto try_to_reuse;
|
||||
}
|
||||
|
||||
if (strcmp(pss->path, endpoints.index) != 0) {
|
||||
lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
|
||||
goto try_to_reuse;
|
||||
|
||||
Reference in New Issue
Block a user