Browse Source

Try alternative for multiple additional_header lines

bel2125 8 years ago
parent
commit
8ae9be92b6
2 changed files with 18 additions and 6 deletions
  1. 1 1
      src/civetweb.c
  2. 17 5
      src/main.c

+ 1 - 1
src/civetweb.c

@@ -13604,7 +13604,7 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 	struct sockaddr *psa = (struct sockaddr *)&(conn->client.rsa.sin);
 #endif
 
-    conn->buf_size = (int)max_req_size;
+	conn->buf_size = (int)max_req_size;
 	conn->buf = (char *)(conn + 1);
 	conn->ctx = &common_client_context;
 	conn->client.sock = sock;

+ 17 - 5
src/main.c

@@ -565,15 +565,27 @@ set_option(char **options, const char *name, const char *value)
 
 	for (i = 0; i < MAX_OPTIONS; i++) {
 		if (options[2 * i] == NULL) {
-            /* Option not set yet. Add new option */
+			/* Option not set yet. Add new option */
 			options[2 * i] = sdup(name);
-            options[2 * i + 1] = sdup(value);
+			options[2 * i + 1] = sdup(value);
 			options[2 * i + 2] = NULL;
 			break;
 		} else if (!strcmp(options[2 * i], name)) {
-            /* Option already set. Overwrite */
-			free(options[2 * i + 1]);
-            options[2 * i + 1] = sdup(value);
+			if (!strcmp(name, "additional_header")) {
+				/* Option already set. Overwrite */
+				char *s =
+				    malloc(strlen(options[2 * i + 1]) + 3 + strlen(value));
+				if (!s) {
+					die("Out of memory");
+				}
+				sprintf(s, "%s\r\n%s", options[2 * i + 1], value);
+				free(options[2 * i + 1]);
+				options[2 * i + 1] = s;
+			} else {
+				/* Option already set. Overwrite */
+				free(options[2 * i + 1]);
+				options[2 * i + 1] = sdup(value);
+			}
 			break;
 		}
 	}