phroxy

Gopher to HTTP proxy
git clone git://git.z3bra.org/phroxy.git
Log | Files | Refs | LICENSE

commit aa14b0f30641e561646bf803aa212a65eefdab1a
parent f73785325b3aa56daa62891ffefa9fc7ef19c9c1
Author: Willy Goiffon <dev@z3bra.org>
Date:   Mon, 21 Sep 2020 15:31:22 +0200

Use image filename extension as mimetype

Diffstat:
Mphroxy.c | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/phroxy.c b/phroxy.c @@ -154,8 +154,10 @@ printhttp(int code) } char * -contenttype(char i) +contenttype(char i, char *path) { + static char *ext, type[12]; + switch(i) { case '0': case '1': @@ -172,7 +174,12 @@ contenttype(char i) return "application/octet-stream"; break; /* NOTREACHED */ case 'I': - return "image/*"; + if (!(ext = strrchr(path, '.'))) + return "image/*"; + + /* assume 4 chars max for extension */ + snprintf(type, 11, "image/%s", ext + 1); + return type; break; /* NOTREACHED */ case 'g': return "image/gif"; @@ -278,7 +285,7 @@ printhtml(int fd, const char *data, size_t len) } int -serveitem(char item, char *data, size_t len) +serveitem(char item, char *path, char *data, size_t len) { char *send; int sent; @@ -384,7 +391,7 @@ phroxy(char *url) return 1; } - serveitem(item, data, len); + serveitem(item, path, data, len); return 0; }