tUse image filename extension as mimetype - phroxy - Gopher to HTTP proxy
 (HTM) git clone git://git.z3bra.org/phroxy.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit aa14b0f30641e561646bf803aa212a65eefdab1a
 (DIR) parent f73785325b3aa56daa62891ffefa9fc7ef19c9c1
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Mon, 21 Sep 2020 15:31:22 +0200
       
       Use image filename extension as mimetype
       
       Diffstat:
         M phroxy.c                            |      15 +++++++++++----
       
       1 file changed, 11 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/phroxy.c b/phroxy.c
       t@@ -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':
       t@@ -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";
       t@@ -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;
       t@@ -384,7 +391,7 @@ phroxy(char *url)
                        return 1;
                }
        
       -        serveitem(item, data, len);
       +        serveitem(item, path, data, len);
        
                return 0;
        }