]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added an implementation of parseFirstLine() for class HttpRequest
authorwessels <>
Mon, 19 Sep 2005 23:30:23 +0000 (23:30 +0000)
committerwessels <>
Mon, 19 Sep 2005 23:30:23 +0000 (23:30 +0000)
src/HttpRequest.cc

index c926f8ddc7e43c0d58a96bc5ac3b8822bf657868..90696661d6e9e7c8313093000d46d9272d007e61 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpRequest.cc,v 1.52 2005/09/17 04:53:44 wessels Exp $
+ * $Id: HttpRequest.cc,v 1.53 2005/09/19 17:30:23 wessels Exp $
  *
  * DEBUG: section 73    HTTP Request
  * AUTHOR: Duane Wessels
@@ -162,8 +162,48 @@ bool HttpRequest::sanityCheckStartLine(MemBuf *buf, http_status *error)
 
 bool HttpRequest::parseFirstLine(const char *start, const char *end)
 {
-    fatal("HttpRequest::parseFirstLine not implemented yet");
-    return false;
+    const char *t = start + strcspn(start, w_space);
+    method = urlParseMethod(start, t);
+
+    if (METHOD_NONE == method)
+        return false;
+
+    start = t + strspn(t, w_space);
+
+    const char *ver = findTrailingHTTPVersion(start, end);
+
+    if (ver) {
+        end = ver - 1;
+
+        while (xisspace(*end)) // find prev non-space
+            end--;
+
+        end++;                 // back to space
+
+        if (2 != sscanf(ver + 5, "%d.%d", &http_ver.major, &http_ver.minor)) {
+            debug(73, 1) ("parseRequestLine: Invalid HTTP identifier.\n");
+            return false;
+        }
+    } else {
+        http_ver.major = 0;
+        http_ver.minor = 9;
+    }
+
+    if (end < start)   // missing URI
+        return false;
+
+    char save = *end;
+
+    * (char *) end = '\0';     // temp terminate URI, XXX dangerous?
+
+    HttpRequest *tmp = urlParse(method, (char *) start, this);
+
+    * (char *) end = save;
+
+    if (NULL == tmp)
+        return false;
+
+    return true;
 }
 
 HttpRequest *