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

Skip URI parameters when serving a directory (http_server) #1677

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/supplemental/http/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ nni_http_handler_set_method(nni_http_handler *h, const char *method)

static nni_list http_servers =
NNI_LIST_INITIALIZER(http_servers, nni_http_server, node);
static nni_mtx http_servers_lk = NNI_MTX_INITIALIZER;
static nni_mtx http_servers_lk = NNI_MTX_INITIALIZER;

static void
http_sc_reap(void *arg)
Expand Down Expand Up @@ -1156,7 +1156,7 @@ nni_http_server_res_error(nni_http_server *s, nni_http_res *res)
http_error *epage;
char * body = NULL;
char * html = NULL;
size_t len = 0;
size_t len = 0;
uint16_t code = nni_http_res_get_status(res);
int rv;

Expand Down Expand Up @@ -1550,7 +1550,10 @@ http_handle_dir(nni_aio *aio)
}

for (uri = uri + len; *uri != '\0'; uri++) {
if (*uri == '/') {
if (*uri == '?') {
// Skip URI parameters
break;
} else if (*uri == '/') {
strcpy(dst, NNG_PLATFORM_DIR_SEP);
dst += sizeof(NNG_PLATFORM_DIR_SEP) - 1;
} else {
Expand Down
22 changes: 22 additions & 0 deletions tests/httpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,24 @@ TestMain("HTTP Server", {
nng_free(data, size);
});

Convey("Named file with URI parameters works", {
char fullurl[256];
void * data;
size_t size;
uint16_t stat;
char * ctype;

snprintf(
fullurl, sizeof(fullurl), "%s/file.txt?param=123456", urlstr);
So(httpget(fullurl, &data, &size, &stat, &ctype) == 0);
So(stat == NNG_HTTP_STATUS_OK);
So(size == strlen(doc2));
So(memcmp(data, doc2, size) == 0);
So(strcmp(ctype, "text/plain") == 0);
nni_strfree(ctype);
nng_free(data, size);
});

Convey("Missing index gives 404", {
char fullurl[256];
void * data;
Expand Down Expand Up @@ -440,6 +458,7 @@ TestMain("HTTP Server", {
nng_url_free(curl);
nng_free(data, size);
});

Convey("Version 0.9 gives 505", {
char fullurl[256];
void * data;
Expand All @@ -462,6 +481,7 @@ TestMain("HTTP Server", {
nng_url_free(curl);
nng_free(data, size);
});

Convey("Missing Host gives 400", {
char fullurl[256];
void * data;
Expand Down Expand Up @@ -643,6 +663,7 @@ TestMain("HTTP Server", {
nng_url_free(curl);
nng_free(data, size);
});

Convey("Version 0.9 gives 505", {
char fullurl[256];
void * data;
Expand All @@ -665,6 +686,7 @@ TestMain("HTTP Server", {
nng_url_free(curl);
nng_free(data, size);
});

Convey("Missing Host gives 400", {
char fullurl[256];
void * data;
Expand Down
Loading