Browse Source

[core] extend dir redirection to take HTTP status

extend http_response_redirect_to_directory to take HTTP status code
and to set Location if HTTP status >= 300, or else set Content-Location
personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
f60f1a279e
  1. 13
      src/http-header-glue.c
  2. 2
      src/mod_userdir.c
  3. 8
      src/mod_webdav.c
  4. 2
      src/response.c
  5. 2
      src/response.h

13
src/http-header-glue.c

@ -91,7 +91,7 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer *
return 0;
}
int http_response_redirect_to_directory(server *srv, connection *con) {
int http_response_redirect_to_directory(server *srv, connection *con, int status) {
buffer *o = srv->tmp_buf;
buffer_copy_buffer(o, con->uri.scheme);
buffer_append_string_len(o, CONST_STR_LEN("://"));
@ -105,10 +105,15 @@ int http_response_redirect_to_directory(server *srv, connection *con) {
buffer_append_string_buffer(o, con->uri.query);
}
http_header_response_set(con, HTTP_HEADER_LOCATION, CONST_STR_LEN("Location"), CONST_BUF_LEN(o));
if (status >= 300) {
http_header_response_set(con, HTTP_HEADER_LOCATION, CONST_STR_LEN("Location"), CONST_BUF_LEN(o));
con->http_status = status;
con->file_finished = 1;
}
else {
http_header_response_set(con, HTTP_HEADER_CONTENT_LOCATION, CONST_STR_LEN("Content-Location"), CONST_BUF_LEN(o));
}
con->http_status = 301;
con->file_finished = 1;
return 0;
}

2
src/mod_userdir.c

@ -215,7 +215,7 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) {
if (NULL == (rel_url = strchr(con->uri.path->ptr + 2, '/'))) {
/* / is missing -> redirect to .../ as we are a user - DIRECTORY ! :) */
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 301);
return HANDLER_FINISHED;
}

8
src/mod_webdav.c

@ -1335,7 +1335,7 @@ static handler_t mod_webdav_propfind(server *srv, connection *con, plugin_data *
}
if (S_ISDIR(sce->st.st_mode) && con->physical.path->ptr[buffer_string_length(con->physical.path)-1] != '/') {
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 308);
return HANDLER_FINISHED;
}
@ -1652,7 +1652,7 @@ static handler_t mod_webdav_delete(server *srv, connection *con, plugin_data *p,
buffer *multi_status_resp;
if (con->physical.path->ptr[buffer_string_length(con->physical.path)-1] != '/') {
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 308);
return HANDLER_FINISHED;
}
@ -2083,7 +2083,7 @@ static handler_t mod_webdav_copymove(server *srv, connection *con, plugin_data *
/* src is a directory */
if (con->physical.path->ptr[buffer_string_length(con->physical.path)-1] != '/') {
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 308);
return HANDLER_FINISHED;
}
@ -2238,7 +2238,7 @@ static handler_t mod_webdav_proppatch(server *srv, connection *con, plugin_data
}
if (S_ISDIR(st.st_mode) && con->physical.path->ptr[buffer_string_length(con->physical.path)-1] != '/') {
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 308);
return HANDLER_FINISHED;
}

2
src/response.c

@ -245,7 +245,7 @@ static handler_t http_response_physical_path_check(server *srv, connection *con)
if (con->uri.path->ptr[buffer_string_length(con->uri.path) - 1] != '/') {
/* redirect to .../ */
http_response_redirect_to_directory(srv, con);
http_response_redirect_to_directory(srv, con, 301);
return HANDLER_FINISHED;
}

2
src/response.h

@ -45,7 +45,7 @@ handler_t http_response_parse_headers(server *srv, connection *con, http_respons
handler_t http_response_read(server *srv, connection *con, http_response_opts *opts, buffer *b, fdnode *fdn);
handler_t http_response_prepare(server *srv, connection *con);
int http_response_buffer_append_authority(server *srv, connection *con, buffer *b);
int http_response_redirect_to_directory(server *srv, connection *con);
int http_response_redirect_to_directory(server *srv, connection *con, int status);
int http_response_handle_cachable(server *srv, connection *con, buffer * mtime);
void http_response_body_clear(connection *con, int preserve_length);
void http_response_send_file (server *srv, connection *con, buffer *path);

Loading…
Cancel
Save