feat(lander): serve content-disposition header
parent
6a5b23afaa
commit
b053aa6c93
|
@ -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 {
|
||||
|
|
|
@ -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] = {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#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) {
|
||||
|
|
Loading…
Reference in New Issue