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:
Daniel Monteiro Basso
2020-03-25 09:12:33 +00:00
committed by GitHub
parent ea27950594
commit 398bebf091
3 changed files with 27 additions and 2 deletions

View File

@@ -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;