From 81cfca6c6ec15e3a8f94e278f2bdfcc1249eb122 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 20 Aug 2010 15:29:54 +0200 Subject: [PATCH] Use new-style (CR-less) headers in responses. --- lib/resp.c | 8 ++++---- src/callcgi.c | 12 ++++++------ src/debugsink.c | 22 +++++++++++----------- src/sendfile.c | 20 ++++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/resp.c b/lib/resp.c index da354f9..63c8eca 100644 --- a/lib/resp.c +++ b/lib/resp.c @@ -74,10 +74,10 @@ void simpleerror(int fd, int code, char *msg, char *fmt, ...) bufcatstr(buf, "\r\n"); free(tmp2); out = fdopen(fd, "w"); - fprintf(out, "HTTP/1.1 %i %s\r\n", code, msg); - fprintf(out, "Content-Type: text/html\r\n"); - fprintf(out, "Content-Length: %zi\r\n", buf.d); - fprintf(out, "\r\n"); + fprintf(out, "HTTP/1.1 %i %s\n", code, msg); + fprintf(out, "Content-Type: text/html\n"); + fprintf(out, "Content-Length: %zi\n", buf.d); + fprintf(out, "\n"); fwrite(buf.b, 1, buf.d, out); fclose(out); buffree(buf); diff --git a/src/callcgi.c b/src/callcgi.c index 70a97dd..9e7c21b 100644 --- a/src/callcgi.c +++ b/src/callcgi.c @@ -258,13 +258,13 @@ static void sendstatus(char **headers, FILE *out) } if(status) { if(strchr(status, ' ')) - fprintf(out, "HTTP/1.1 %s\r\n", status); + fprintf(out, "HTTP/1.1 %s\n", status); else - fprintf(out, "HTTP/1.1 %i %s\r\n", atoi(status), defstatus(atoi(status))); + fprintf(out, "HTTP/1.1 %i %s\n", atoi(status), defstatus(atoi(status))); } else if(location) { - fprintf(out, "HTTP/1.1 303 See Other\r\n"); + fprintf(out, "HTTP/1.1 303 See Other\n"); } else { - fprintf(out, "HTTP/1.1 200 OK\r\n"); + fprintf(out, "HTTP/1.1 200 OK\n"); } } @@ -272,7 +272,7 @@ static void sendheaders(char **headers, FILE *out) { while(*headers) { if(**headers) - fprintf(out, "%s: %s\r\n", headers[0], headers[1]); + fprintf(out, "%s: %s\n", headers[0], headers[1]); headers += 2; } } @@ -329,7 +329,7 @@ int main(int argc, char **argv, char **envp) } sendstatus(headers, stdout); sendheaders(headers, stdout); - printf("\r\n"); + printf("\n"); passdata(out, stdout); return(0); } diff --git a/src/debugsink.c b/src/debugsink.c index eb389f3..dee8c98 100644 --- a/src/debugsink.c +++ b/src/debugsink.c @@ -47,9 +47,9 @@ int main(int argc, char **argv) printf("%s %s %s %s %s\n", req->method, req->url, req->ver, req->rest, getheader(req, "x-ash-address")); out = fdopen(fd, "w"); if(!strcmp(req->rest, "")) { - fprintf(out, "HTTP/1.1 200 OK\r\n"); - fprintf(out, "Content-Type: text/html; charset=utf8\r\n"); - fprintf(out, "\r\n"); + fprintf(out, "HTTP/1.1 200 OK\n"); + fprintf(out, "Content-Type: text/html; charset=utf8\n"); + fprintf(out, "\n"); fprintf(out, "\n\n
\n\n
\n\n\n"); } else if(!strcmp(req->rest, "post")) { nb = 0; @@ -61,19 +61,19 @@ int main(int argc, char **argv) break; nb += ret; } - fprintf(out, "HTTP/1.1 200 OK\r\n"); - fprintf(out, "Content-Type: text/plain; charset=utf8\r\n"); - fprintf(out, "\r\n"); + fprintf(out, "HTTP/1.1 200 OK\n"); + fprintf(out, "Content-Type: text/plain; charset=utf8\n"); + fprintf(out, "\n"); fprintf(out, "%i\n", (int)nb); } else if(!strcmp(req->rest, "inf")) { - fprintf(out, "HTTP/1.1 200 OK\r\n"); - fprintf(out, "Content-Type: text/plain\r\n"); - fprintf(out, "\r\n"); + fprintf(out, "HTTP/1.1 200 OK\n"); + fprintf(out, "Content-Type: text/plain\n"); + fprintf(out, "\n"); while(1) fprintf(out, "0123456789012345678901234567890123456789012345678901234567890123456789\n"); } else { - fprintf(out, "HTTP/1.1 404 Not Found\r\n"); - fprintf(out, "\r\n"); + fprintf(out, "HTTP/1.1 404 Not Found\n"); + fprintf(out, "\n"); } fclose(out); } diff --git a/src/sendfile.c b/src/sendfile.c index 601661b..48787fd 100644 --- a/src/sendfile.c +++ b/src/sendfile.c @@ -120,10 +120,10 @@ static void checkcache(char *file, struct stat *sb) if((hdr = getenv("REQ_IF_MODIFIED_SINCE")) != NULL) { if(parsehttpdate(hdr) < sb->st_mtime) return; - printf("HTTP/1.1 304 Not Modified\r\n"); - printf("Date: %s\r\n", fmthttpdate(time(NULL))); - printf("Content-Length: 0\r\n"); - printf("\r\n"); + printf("HTTP/1.1 304 Not Modified\n"); + printf("Date: %s\n", fmthttpdate(time(NULL))); + printf("Content-Length: 0\n"); + printf("\n"); exit(0); } } @@ -175,12 +175,12 @@ int main(int argc, char **argv) checkcache(file, &sb); - printf("HTTP/1.1 200 OK\r\n"); - printf("Content-Type: %s\r\n", contype); - printf("Content-Length: %ji\r\n", (intmax_t)sb.st_size); - printf("Last-Modified: %s\r\n", fmthttpdate(sb.st_mtime)); - printf("Date: %s\r\n", fmthttpdate(time(NULL))); - printf("\r\n"); + printf("HTTP/1.1 200 OK\n"); + printf("Content-Type: %s\n", contype); + printf("Content-Length: %ji\n", (intmax_t)sb.st_size); + printf("Last-Modified: %s\n", fmthttpdate(sb.st_mtime)); + printf("Date: %s\n", fmthttpdate(time(NULL))); + printf("\n"); fflush(stdout); if(strcasecmp(argv[optind], "head")) passdata(fd, 1); -- 2.11.0