Substitute missing strcasestr(3)
[middleman.git] / src / protocol.c
index 9f186ce..e89938a 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <ctype.h>
 #include "../libntlm/ntlm.h"
 #include "proto.h"
 
@@ -395,11 +396,17 @@ int protocol_http(CONNECTION * connection)
                FREE_AND_NULL(connection->rheader->content_encoding);
                if (connection->header->accept_encoding != NULL) {
                        /* compress the content if the browser supports gzip encoding */
-                       ptr = strcasestr(connection->header->accept_encoding, "gzip");
+                       char *s, *accept_encoding_lower = xstrdup(connection->header->accept_encoding);
+
+                       /* strcasestr(3) is not available on some systems; use strstr(3) instead */
+                       for (s=accept_encoding_lower; *s; s++)
+                               *s=tolower(*s);
+                       ptr = strstr(accept_encoding_lower, "gzip");
                        if (ptr != NULL) {
                                ret = filebuf_gzip(filebuf);
                                if (ret == TRUE) connection->rheader->content_encoding = xstrdup("gzip");
                        }
+                       free(accept_encoding_lower);
                }
  
                bypass: