]> err.no Git - varnish/commitdiff
Make the HTTP expect work for trivial cases.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 19:52:34 +0000 (19:52 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 19:52:34 +0000 (19:52 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2688 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/t000.vtc
varnish-cache/bin/varnishtest/vtc_http.c

index d766663bb7092c353e332185b6e111ea28464382..e3bd174fb399d5bbbd566ee004eeb18aff0e9ae2 100644 (file)
@@ -14,7 +14,7 @@ client c1 -connect localhost:9080 {
        txreq 
        rxresp
        expect resp.status == 200
-       expect resp.length == 10
+       expect resp.http.foobar == barf
 }
 
 client c1 -run
index 4c2b0a691945bf2831cc16a2caeb5e001a8b9e68..768589b44c85775034054194027ee8cbfc883bea 100644 (file)
@@ -62,18 +62,79 @@ struct http {
  * Expect
  */
 
+static char *
+cmd_var_resolve(struct http *hp, char *spec)
+{
+       char **hh, *hdr;
+       int n, l;
+
+       if (!strcmp(spec, "req.request"))
+               return(hp->req[0]);
+       if (!strcmp(spec, "req.url"))
+               return(hp->req[1]);
+       if (!strcmp(spec, "req.proto"))
+               return(hp->req[2]);
+       if (!strcmp(spec, "resp.proto"))
+               return(hp->resp[0]);
+       if (!strcmp(spec, "resp.status"))
+               return(hp->resp[1]);
+       if (!strcmp(spec, "resp.msg"))
+               return(hp->resp[2]);
+       if (!memcmp(spec, "req.http.", 9)) {
+               hh = hp->req;
+               hdr = spec + 9;
+       } else if (!memcmp(spec, "resp.http.", 10)) {
+               hh = hp->resp;
+               hdr = spec + 10;
+       } else
+               return (spec);
+       l = strlen(hdr);
+       for (n = 3; hh[n] != NULL; n++) {
+               if (strncasecmp(hdr, hh[n], l) || hh[n][l] != ':')
+                       continue;
+               hdr = hh[n] + l + 1;
+               while (vct_issp(*hdr))
+                       hdr++;
+               return (hdr);
+       }
+       return (spec);
+}
+
 static void
 cmd_http_expect(char **av, void *priv)
 {
        struct http *hp;
+       char *lhs;
+       char *cmp;
+       char *rhs;
 
        CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
        assert(!strcmp(av[0], "expect"));
        av++;
 
-       for(; *av != NULL; av++) {
-               fprintf(stderr, "Unknown http expect spec: %s\n", *av);
-               // exit (1);
+       AN(av[0]);
+       AN(av[1]);
+       AN(av[2]);
+       AZ(av[3]);
+       lhs = cmd_var_resolve(hp, av[0]);
+       cmp = av[1];
+       rhs = cmd_var_resolve(hp, av[2]);
+       if (!strcmp(cmp, "==")) {
+               if (strcmp(lhs, rhs)) {
+                       fprintf(stderr, 
+                           "---- %-4s EXPECT %s (%s) %s %s (%s) failed\n",
+                           hp->ident, av[0], lhs, av[1], av[2], rhs);
+                       exit (1);
+               } else {
+                       printf(
+                           "#### %-4s EXPECT %s (%s) %s %s (%s) match\n",
+                           hp->ident, av[0], lhs, av[1], av[2], rhs);
+               }
+       } else {
+               fprintf(stderr, 
+                   "---- %-4s EXPECT %s (%s) %s %s (%s) not implemented\n",
+                   hp->ident, av[0], lhs, av[1], av[2], rhs);
+               exit (1);
        }
 }