Use CRLF instead of just LF for headers in GET requests

This commit is contained in:
Simon Robertshaw
2012-05-09 21:07:17 +01:00
parent 60e31ac78d
commit aeb383742f

View File

@@ -6,7 +6,7 @@
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
@@ -15,7 +15,8 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/ */
@@ -298,8 +299,8 @@ void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
void http_async_add_header(void *ctx, char *name, char *data) void http_async_add_header(void *ctx, char *name, char *data)
{ {
struct http_ctx *cx = ctx; struct http_ctx *cx = ctx;
cx->thdr = realloc(cx->thdr, cx->thlen + strlen(name) + strlen(data) + 4); cx->thdr = realloc(cx->thdr, cx->thlen + strlen(name) + strlen(data) + 5);
cx->thlen += sprintf(cx->thdr+cx->thlen, "%s: %s\n", name, data); cx->thlen += sprintf(cx->thdr+cx->thlen, "%s: %s\r\n", name, data);
} }
static void process_header(struct http_ctx *cx, char *str) static void process_header(struct http_ctx *cx, char *str)
@@ -467,13 +468,13 @@ int http_async_req_status(void *ctx)
if (cx->txdl) if (cx->txdl)
{ {
// generate POST // generate POST
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 121 + cx->txdl + cx->thlen); cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 127 + cx->txdl + cx->thlen);
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\r\n", cx->path);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
if (!cx->keep) if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
if (cx->thdr) if (cx->thdr)
{ {
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
@@ -482,13 +483,13 @@ int http_async_req_status(void *ctx)
cx->thdr = NULL; cx->thdr = NULL;
cx->thlen = 0; cx->thlen = 0;
} }
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl);
#ifdef BETA #ifdef BETA
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#else #else
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#endif #endif
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl; cx->tlen += cx->txdl;
free(cx->txd); free(cx->txd);
@@ -498,11 +499,11 @@ int http_async_req_status(void *ctx)
else else
{ {
// generate GET // generate GET
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 89 + cx->thlen); cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 95 + cx->thlen);
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\r\n", cx->path);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
if (cx->thdr) if (cx->thdr)
{ {
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
@@ -512,13 +513,13 @@ int http_async_req_status(void *ctx)
cx->thlen = 0; cx->thlen = 0;
} }
if (!cx->keep) if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
#ifdef BETA #ifdef BETA
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#else #else
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#endif #endif
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
} }
cx->state = HTS_XMIT; cx->state = HTS_XMIT;
cx->last = now; cx->last = now;
@@ -913,7 +914,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
plens[i] = strlen(parts[i]); plens[i] = strlen(parts[i]);
} }
retry: retry:
if (blen >= 31) if (blen >= 31)
goto fail; goto fail;
memset(map, 0, 62*sizeof(int)); memset(map, 0, 62*sizeof(int));