diff --git a/include/http/types.h b/include/http/types.h index 5b75bea..cccf0a0 100644 --- a/include/http/types.h +++ b/include/http/types.h @@ -124,7 +124,8 @@ extern const char *http_header_names[]; typedef enum http_header { http_header_connection = 0, http_header_location, - http_header_content_type + http_header_content_type, + http_header_content_disposition } http_header; typedef enum http_body_type { diff --git a/src/http/http_consts.c b/src/http/http_consts.c index 6a6e15c..8aa6f4b 100644 --- a/src/http/http_consts.c +++ b/src/http/http_consts.c @@ -96,7 +96,8 @@ const char *http_status_names[][32] = { const char *http_header_names[] = { "Connection", "Location", - "Content-Type" + "Content-Type", + "Content-Disposition" }; const char *http_mime_type_names[][2] = { diff --git a/src/lander/lander_get.c b/src/lander/lander_get.c index 1fb1603..102c631 100644 --- a/src/lander/lander_get.c +++ b/src/lander/lander_get.c @@ -1,6 +1,7 @@ #include #include "event_loop.h" +#include "http/res.h" #include "http/types.h" #include "lander.h" #include "log.h" @@ -75,6 +76,21 @@ void lander_get_file(event_loop_conn *conn) { ctx->res.body.expected_len = lsm_entry_data_len(c_ctx->entry); lander_attr_to_header(ctx, lander_attr_type_content_type, http_header_content_type); + + lsm_str *value; + char *buf; + + if (lsm_entry_attr_get(&value, c_ctx->entry, lander_attr_type_file_name) == + lsm_error_ok) { + buf = malloc(24 + lsm_str_len(value)); + int len = lsm_str_len(value); + sprintf(buf, "attachment; filename=\"%*s\"", len, lsm_str_ptr(value)); + } else { + buf = malloc(11); + strcpy(buf, "attachment"); + } + + http_res_add_header(&ctx->res, http_header_content_disposition, buf, true); } bool lander_get_entry(event_loop_conn *conn) {