liquidwar-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[liquidwar-user] patch use HTTP/1.1 rather than HTTP/0.9


From: Roderick Schertler
Subject: [liquidwar-user] patch use HTTP/1.1 rather than HTTP/0.9
Date: Mon, 10 Feb 2003 13:48:51 -0500

The meta server functions didn't work for me.  There's a transparent
Squid proxy between me and the Internet, the problem was that it didn't
like the HTTP/0.9 requests which the client was sending.  Even though I
think Squid is supposed to support HTTP/0.9, I couldn't get it to work.

Here's a patch which causes liquidwar use HTTP/1.1 instead of HTTP/0.9.

diff -ur base.0.orig/src/httputil.c base.2.http-1.1/src/httputil.c
--- base.0.orig/src/httputil.c  2002-12-16 04:55:47.000000000 -0500
+++ base.2.http-1.1/src/httputil.c      2003-02-07 14:32:43.000000000 -0500
@@ -69,8 +69,13 @@
 #define LW_HTTPUTIL_PORT              80
 #define LW_HTTPUTIL_HOST_SIZE         200
 #define LW_HTTPUTIL_REQUEST_SIZE      1000
-#define LW_HTTPUTIL_GET_HTTP          "GET http://";
 #define LW_HTTPUTIL_EMPTY_LINES_LIMIT 10
+#define LW_HTTPUTIL_GET_CMD \
+    "GET http://%s HTTP/1.1\x0d\x0a" \
+    "Host: %s\x0d\x0a" \
+    "Connection: close\x0d\x0a" \
+    /* additional CR+LF supplied by lw_sock_send_str() */
+
 
 /*==================================================================*/
 /* static functions                                                 */
@@ -107,11 +112,12 @@
       (*search)='\0';
     }
   
-  strcpy(request,LW_HTTPUTIL_GET_HTTP);
-  if (strlen(url)+strlen(request)<LW_HTTPUTIL_REQUEST_SIZE)
+  if (strlen(LW_HTTPUTIL_GET_CMD) - 4 /* 2*%s */ + 1 /* \0 */
+      + strlen(host) + strlen(url) > LW_HTTPUTIL_REQUEST_SIZE)
     {
-      strcat(request,url);
+      return result;
     }
+  sprintf(request,LW_HTTPUTIL_GET_CMD,url,host);
 
   if (lw_dnsutil_name_to_ip(ip,host))
     {
@@ -119,25 +125,49 @@
        {
          if (lw_sock_send_str(sock,request))
            {
-             while (lw_sock_recv_str(sock,data)==1 && 
-                    empty_lines<LW_HTTPUTIL_EMPTY_LINES_LIMIT)
+             result = 1;
+             /* read status line */
+             if (result && !lw_sock_recv_str(sock,data))
+               {
+                 result = 0;
+                 if (100 < size)
+                   sprintf(content,"Failed to read status line\n");
+               }
+             /* make sure status code starts with 2 */
+             if (result && !((search = strchr(data,' ')) && search[1]=='2'))
                {
-                 if (strlen(content)+strlen(data)<size-2)
+                 result = 0;
+                 if (100 + strlen(host) + strlen(data) < size)
                    {
-                     strcat(content,data);
-                     strcat(content,"\n");
+                     sprintf(content, "Failure from web server %s: %s\n",
+                             host,data);
                    }
-                 if (strlen(data)==0)
+               }
+             if (result)
+               {
+                 /* skip past headers */
+                 while (lw_sock_recv_str(sock,data) && data[0])
+                   ;
+                 while (lw_sock_recv_str(sock,data)==1 && 
+                        empty_lines<LW_HTTPUTIL_EMPTY_LINES_LIMIT)
                    {
-                     empty_lines++;
+                     if (strlen(content)+strlen(data)<size-2)
+                       {
+                         strcat(content,data);
+                         strcat(content,"\n");
+                       }
+                     if (strlen(data)==0)
+                       {
+                         empty_lines++;
+                       }
+                     result=1;
                    }
-                 result=1;
                }
            }
 
          lw_sock_close(&sock);
 
-         if (!result)
+         if (!result && !content[0])
            {
              if (size>strlen(request)+100)
                {
diff -ur base.0.orig/src/sockex.c base.2.http-1.1/src/sockex.c
--- base.0.orig/src/sockex.c    2002-12-16 04:55:48.000000000 -0500
+++ base.2.http-1.1/src/sockex.c        2003-02-03 12:00:16.000000000 -0500
@@ -174,7 +174,7 @@
  * Sends a string on the network.
  * The advantage of this function over a raw "send" is that it does
  * a "strlen" automatically to know the length of the string, and
- * adds a tailing "\n" so that the message is "telnet compliant"
+ * adds a tailing CR+LF so that the message is "telnet/http compliant"
  */
 int lw_sock_send_str_ex(int sock, char *str)
 {
@@ -193,12 +193,14 @@
 
       /*
        * We put the string in a buffer, since we'll probably have
-       * to modify it (cut if it's too long, add a tailing '\n').
+       * to modify it (cut if it's too long, add a tailing CR+LF).
        */
       len=strlen(str);
-      len=MIN(len,LW_SOCK_MESSAGE_SIZE-2);
+      len=MIN(len,LW_SOCK_MESSAGE_SIZE-3);
       strncpy(buffer,str,len);
-      buffer[len]='\n';
+      buffer[len]='\x0d';
+      ++len;
+      buffer[len]='\x0a';
       ++len;
       buffer[len]='\0';  
 
-- 
Roderick Schertler
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]