summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2024-05-13 22:04:01 +0200
committerVincent Douillet <vincent@vdouillet.fr>2024-05-13 22:31:42 +0200
commit4be89075c5bb5793f8c79da8f8df1accc1f0168f (patch)
tree6407385f4d4827651a10a495f829a6bfa0109f3a /http.c
parent10eb77f9323110c55f88195c5b8207eb524baa73 (diff)
fix encodings in headers and file paths
Diffstat (limited to 'http.c')
-rw-r--r--http.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/http.c b/http.c
index b79b361..ef8d90c 100644
--- a/http.c
+++ b/http.c
@@ -34,16 +34,30 @@
#include "http.h"
#include "mime.h"
+#include "str.h"
-void
+bool
http_open_file(struct kreq * r, enum khttp code, struct file * f)
{
+ char *filename;
+
+ /* file name needs to be url encoded for special chars */
+ filename = khttp_urlencode(f->name);
+ if (filename == NULL)
+ return false;
+
+ /* but for some reason, spaces should remain spaces... */
+ str_replace(filename, '+', ' ');
+
khttp_head(r, kresps[KRESP_STATUS], "%s", khttps[code]);
khttp_head(r, kresps[KRESP_CONTENT_DISPOSITION],
- "attachment;filename=\"%s\"", f->name);
+ "attachment;filename=\"%s\"", filename);
+ free(filename);
khttp_head(r, kresps[KRESP_CONTENT_TYPE], "%s", mime_str(f->mime));
khttp_head(r, kresps[KRESP_CONTENT_LENGTH], "%zu", f->size);
- khttp_body_compress(r, 0); /* file is not compressed */
+ khttp_body_compress(r, 0); /* file is not compressed */
+
+ return true;
}
void