35b5c5
diff --git a/src/http.c b/src/http.c
35b5c5
index b45c404..aa4fd25 100644
35b5c5
--- a/src/http.c
35b5c5
+++ b/src/http.c
35b5c5
@@ -605,9 +605,9 @@ struct response {
35b5c5
    resp_header_*.  */
35b5c5
 
35b5c5
 static struct response *
35b5c5
-resp_new (const char *head)
35b5c5
+resp_new (char *head)
35b5c5
 {
35b5c5
-  const char *hdr;
35b5c5
+  char *hdr;
35b5c5
   int count, size;
35b5c5
 
35b5c5
   struct response *resp = xnew0 (struct response);
35b5c5
@@ -636,15 +636,23 @@ resp_new (const char *head)
35b5c5
         break;
35b5c5
 
35b5c5
       /* Find the end of HDR, including continuations. */
35b5c5
-      do
35b5c5
+      for (;;)
35b5c5
         {
35b5c5
-          const char *end = strchr (hdr, '\n');
35b5c5
+          char *end = strchr (hdr, '\n');
35b5c5
+
35b5c5
           if (end)
35b5c5
             hdr = end + 1;
35b5c5
           else
35b5c5
             hdr += strlen (hdr);
35b5c5
+
35b5c5
+          if (*hdr != ' ' && *hdr != '\t')
35b5c5
+            break;
35b5c5
+
35b5c5
+          // continuation, transform \r and \n into spaces
35b5c5
+          *end = ' ';
35b5c5
+          if (end > head && end[-1] == '\r')
35b5c5
+            end[-1] = ' ';
35b5c5
         }
35b5c5
-      while (*hdr == ' ' || *hdr == '\t');
35b5c5
     }
35b5c5
   DO_REALLOC (resp->headers, size, count + 1, const char *);
35b5c5
   resp->headers[count] = NULL;