[links-list] http small patch

Witold Filipczyk juandon at poczta.onet.pl
Fri Apr 19 10:15:14 PDT 2002


OK. I did small patch in http.c
I think it is better than was before
(faster or at least executable is smaller).

BTW, I'll do support for gzipped files and Content-Encoding: gzip, x-gzip.



-- 
Witold Filipczyk
-------------- next part --------------
--- src/protocol/http/http.c.orig	Fri Apr 19 16:43:41 2002
+++ src/protocol/http/http.c	Fri Apr 19 18:06:58 2002
@@ -232,6 +232,9 @@
 		
 		/* Nop, this doesn't stand for EuroURL, but Encoded URL. */
 		unsigned char *eurl;
+		unsigned char *cur_p;
+		unsigned int count_spaces = 0;
+		unsigned char *neurl, *neurl_p;
 		
 		if (!post) {
 			eurl = stracpy(url_data);
@@ -240,7 +243,7 @@
 		}
 		
 		/* XXX: This is pretty ugly and ineffective (read as slow). */
-		while (strchr(eurl, ' ')) {
+/*		while (strchr(eurl, ' ')) {
 			unsigned char *space = strchr(eurl, ' ');
 			unsigned char *neurl = mem_alloc(strlen(eurl) + 3);
 			
@@ -252,11 +255,34 @@
 			mem_free(eurl);
 			eurl = neurl;
 		}
+*/
+		/* counts spaces, every space increase length by(in?) 2 bytes,
+		but mem_alloc is called only once */
 		
-		add_to_str(&hdr, &l, eurl);
-		mem_free(eurl);
-	}
+		for (cur_p = eurl; *cur_p; cur_p++)
+			if (*cur_p == ' ') count_spaces++;
+		if (count_spaces) {
 
+			neurl = mem_alloc(cur_p - eurl + (count_spaces << 1) + 1);
+			if (!neurl) goto AAAA;
+			cur_p = eurl;
+			neurl_p = neurl;
+			for (; *cur_p; cur_p++,neurl_p++) {
+				if (*cur_p == ' ') {
+					*neurl_p++ = '%';
+					*neurl_p++ = '2';
+					*neurl_p = '0';
+				}
+				else (*neurl_p = *cur_p);
+			}
+			*neurl_p = 0;
+			add_to_str(&hdr, &l, neurl);
+			mem_free(neurl);
+		}
+		else add_to_str(&hdr, &l, eurl);
+	AAAA:	mem_free(eurl);
+	}
+	
 	if (http10) {
 		add_to_str(&hdr, &l, " HTTP/1.0\r\n");
 	} else {


More information about the links-list mailing list