]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] removed the SN_POST flag and string checks on method
authorWilly Tarreau <w@1wt.eu>
Sun, 17 Dec 2006 12:50:27 +0000 (13:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 17 Dec 2006 12:50:27 +0000 (13:50 +0100)
Now that hreq.meth is known, use it everywhere a method is required.

include/types/session.h
src/proto_http.c

index a1530193a602ef131fc77f91e0103ba3d8850559..9a04994d9f1ff49d9b8be7498dc22ac3720b577a 100644 (file)
@@ -45,7 +45,7 @@
 #define SN_CLALLOW     0x00000004      /* a client header matches an allow regex */
 #define SN_SVDENY      0x00000008      /* a server header matches a deny regex */
 #define SN_SVALLOW     0x00000010      /* a server header matches an allow regex */
-#define        SN_POST         0x00000020      /* the request was an HTTP POST */
+#define SN_UNUSED_1    0x00000020      /* unused bit */
 
 /* session flags dedicated to cookies : bits values 0x40, 0x80 (0-3 shift 6) */
 #define        SN_CK_NONE      0x00000000      /* this session had no cookie */
index e6e4ca7a0d217a44cadbab41ad217588d7f49ff3..b2d620938a16b0640b37f3e610891a14ed4f8327 100644 (file)
@@ -907,7 +907,6 @@ int process_cli(struct session *t)
 
                t->hreq.start.str = req->data + t->hreq.sor;      /* start of the REQURI */
                t->hreq.start.len = t->hreq.hdr_idx.v[t->hreq.hdr_idx.v[0].next].len; /* end of the REQURI */
-
                t->hreq.meth = find_http_meth(t->hreq.start.str, t->hreq.start.len);
 
                do {
@@ -920,8 +919,6 @@ int process_cli(struct session *t)
                                /* the start line might have been modified */
                                t->hreq.start.len = t->hreq.hdr_idx.v[t->hreq.hdr_idx.v[0].next].len;
                                t->hreq.meth = find_http_meth(t->hreq.start.str, t->hreq.start.len);
-
-                               t->hreq.meth = find_http_meth(t->hreq.start.str, t->hreq.start.len);
                        }
 
                        /* has the request been denied ? */
@@ -957,19 +954,7 @@ int process_cli(struct session *t)
                 */
 
 
-               /*
-                * 3: save a pointer to the first line as the request, and
-                * check the method (needed for cookies).
-                */
-
-               t->hreq.start.str = req->data + t->hreq.sor;      /* start of the REQURI */
-               t->hreq.start.len = t->hreq.hdr_idx.v[t->hreq.hdr_idx.v[0].next].len; /* end of the REQURI */
 
-               if (t->hreq.meth == HTTP_METH_POST) {
-                       /* this is a POST request, which is not cacheable by default */
-                       t->flags |= SN_POST;
-               }
-                   
 
                /*
                 * 4: the appsession cookie was looked up very early in 1.2,
@@ -1004,10 +989,10 @@ int process_cli(struct session *t)
                 * 6: check if the user tries to access a protected URI.
                 */
                if (t->be->uri_auth != NULL
+                   && t->hreq.meth == HTTP_METH_GET
                    && t->hreq.start.len >= t->be->uri_auth->uri_len + 4) {   /* +4 for "GET /" */
                        if (!memcmp(t->hreq.start.str + 4,
-                                   t->be->uri_auth->uri_prefix, t->be->uri_auth->uri_len)
-                           && !memcmp(t->hreq.start.str, "GET ", 4)) {
+                            t->be->uri_auth->uri_prefix, t->be->uri_auth->uri_len)) {
                                struct user_auth *user;
                                int authenticated;
                                char *h;
@@ -1809,7 +1794,7 @@ int process_srv(struct session *t)
                                /* we'll have something else to do here : add new headers ... */
 
                                if ((t->srv) && !(t->flags & SN_DIRECT) && (t->be->options & PR_O_COOK_INS) &&
-                                   (!(t->be->options & PR_O_COOK_POST) || (t->flags & SN_POST))) {
+                                   (!(t->be->options & PR_O_COOK_POST) || (t->hreq.meth == HTTP_METH_POST))) {
                                        /* the server is known, it's not the one the client requested, we have to
                                         * insert a set-cookie here, except if we want to insert only on POST
                                         * requests and this one isn't. Note that servers which don't have cookies
@@ -1927,7 +1912,7 @@ int process_srv(struct session *t)
                                         *    unless the response includes appropriate
                                         *    Cache-Control or Expires header fields."
                                         */
-                                       if (!(t->flags & SN_POST) && (t->be->options & PR_O_CHK_CACHE))
+                                       if (!(t->hreq.meth == HTTP_METH_POST) && (t->be->options & PR_O_CHK_CACHE))
                                                t->flags |= SN_CACHEABLE | SN_CACHE_COOK;
                                        break;
                                default:
@@ -3520,7 +3505,7 @@ void get_srv_from_appsession(struct session *t, const char *begin, const char *e
        char *request_line;
 
        if (t->be->appsession_name == NULL ||
-           (memcmp(begin, "GET ", 4) != 0 && memcmp(begin, "POST ", 5) != 0) ||
+           (t->hreq.meth != HTTP_METH_GET && t->hreq.meth != HTTP_METH_POST) ||
            (request_line = memchr(begin, ';', end - begin)) == NULL ||
            ((1 + t->be->appsession_name_len + 1 + t->be->appsession_len) > (end - request_line)))
                return;