]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] replace srv_close_with_err() with http_server_error()
authorWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 19:20:08 +0000 (20:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 19:28:57 +0000 (20:28 +0100)
The new function looks like the previous one except that it operates
at the stream interface level and assumes an already closed SI.

Also remove some old unused occurrences of srv_close_with_err().

include/proto/proto_http.h
src/backend.c
src/proto_http.c

index 5b0df84f8938403b67acf1ec7715a296552de328..3addf3f2523c5b7bf3f4b8ae16318cee449e8058 100644 (file)
@@ -65,9 +65,6 @@ int process_srv_conn(struct session *t);
 int process_request(struct session *t);
 int process_response(struct session *t);
 
-void srv_close_with_err(struct session *t, int err, int finst,
-                       int status, const struct chunk *msg);
-
 int produce_content(struct session *s);
 int produce_content_stats(struct session *s);
 int produce_content_stats_proxy(struct session *s, struct proxy *px);
index 0d6fef12f221a7d90a92b4d3f788fc9ea8f82756..e9125b46d1d49627b8cc3539445242b673c6892e 100644 (file)
@@ -1868,10 +1868,6 @@ int srv_redispatch_connect(struct session *t)
                        goto redispatch;
                }
 
-               //t->req->wex = TICK_ETERNITY;
-               //srv_close_with_err(t, SN_ERR_SRVTO, SN_FINST_Q,
-               //                 503, error_message(t, HTTP_ERR_503));
-
                if (!t->req->cons->err_type) {
                        t->req->cons->err_type = SI_ET_QUEUE_ERR;
                        t->req->cons->err_loc = t->srv;
@@ -1883,10 +1879,6 @@ int srv_redispatch_connect(struct session *t)
 
        case SRV_STATUS_NOSRV:
                /* note: it is guaranteed that t->srv == NULL here */
-               //t->req->wex = TICK_ETERNITY;
-               //srv_close_with_err(t, SN_ERR_SRVTO, SN_FINST_C,
-               //                 503, error_message(t, HTTP_ERR_503));
-
                if (!t->req->cons->err_type) {
                        t->req->cons->err_type = SI_ET_CONN_ERR;
                        t->req->cons->err_loc = NULL;
@@ -1903,10 +1895,6 @@ int srv_redispatch_connect(struct session *t)
 
        case SRV_STATUS_INTERNAL:
        default:
-               //t->req->wex = TICK_ETERNITY;
-               //srv_close_with_err(t, SN_ERR_INTERNAL, SN_FINST_C,
-               //                 500, error_message(t, HTTP_ERR_500));
-
                if (!t->req->cons->err_type) {
                        t->req->cons->err_type = SI_ET_CONN_OTHER;
                        t->req->cons->err_loc = t->srv;
index b8e4daa087af9be5e0a48f40e5020eb5509a7407..3991e41e85015d91268d8fea082598a9d2666b42 100644 (file)
@@ -535,20 +535,21 @@ int http_find_header(const char *name,
        return http_find_header2(name, strlen(name), sol, idx, ctx);
 }
 
-/* This function shuts down the buffers on the server side, and sets indicators
- * accordingly. The server's fd is supposed to already be closed. Note that if
- * <status> is 0, or if the message pointer is NULL, then no message is returned.
+/* This function handles a server error at the stream interface level. The
+ * stream interface is assumed to be already in a closed state. An optional
+ * message is copied into the input buffer, and an HTTP status code stored.
+ * The error flags are set to the values in arguments. Any pending request
+ * is flushed.
  */
-void srv_close_with_err(struct session *t, int err, int finst,
-                       int status, const struct chunk *msg)
+static void http_server_error(struct session *t, struct stream_interface *si,
+                             int err, int finst, int status, const struct chunk *msg)
 {
-       buffer_write_ena(t->rep);
-       t->req->cons->shutw(t->req->cons);
-       t->req->cons->shutr(t->req->cons);
+       buffer_flush(si->ob);
+       buffer_flush(si->ib);
+       buffer_write_ena(si->ib);
        if (status > 0 && msg) {
                t->txn.status = status;
-               if (t->fe->mode == PR_MODE_HTTP)
-                       stream_int_return(t->rep->cons, msg);
+               buffer_write(si->ib, msg->str, msg->len);
        }
        if (!(t->flags & SN_ERR_MASK))
                t->flags |= err;
@@ -688,7 +689,7 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
        si->state    = SI_ST_CLO;
 
        /* send the message */
-       srv_close_with_err(s, SN_ERR_PRXCOND, SN_FINST_C, 302, &rdr);
+       http_server_error(s, si, SN_ERR_PRXCOND, SN_FINST_C, 302, &rdr);
 
        /* FIXME: we should increase a counter of redirects per server and per backend. */
        if (s->srv)
@@ -706,29 +707,29 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
  */
 void return_srv_error(struct session *s, int err_type)
 {
-       s->req->wex = TICK_ETERNITY;
+       struct stream_interface *si = &s->si[1];
 
        if (err_type & SI_ET_QUEUE_ABRT)
-               srv_close_with_err(s, SN_ERR_CLICL, SN_FINST_Q,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_CLICL, SN_FINST_Q,
+                                 503, error_message(s, HTTP_ERR_503));
        else if (err_type & SI_ET_CONN_ABRT)
-               srv_close_with_err(s, SN_ERR_CLICL, SN_FINST_C,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_CLICL, SN_FINST_C,
+                                 503, error_message(s, HTTP_ERR_503));
        else if (err_type & SI_ET_QUEUE_TO)
-               srv_close_with_err(s, SN_ERR_SRVTO, SN_FINST_Q,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_SRVTO, SN_FINST_Q,
+                                 503, error_message(s, HTTP_ERR_503));
        else if (err_type & SI_ET_QUEUE_ERR)
-               srv_close_with_err(s, SN_ERR_SRVCL, SN_FINST_Q,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_SRVCL, SN_FINST_Q,
+                                 503, error_message(s, HTTP_ERR_503));
        else if (err_type & SI_ET_CONN_TO)
-               srv_close_with_err(s, SN_ERR_SRVTO, SN_FINST_C,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_SRVTO, SN_FINST_C,
+                                 503, error_message(s, HTTP_ERR_503));
        else if (err_type & SI_ET_CONN_ERR)
-               srv_close_with_err(s, SN_ERR_SRVCL, SN_FINST_C,
-                                  503, error_message(s, HTTP_ERR_503));
+               http_server_error(s, si, SN_ERR_SRVCL, SN_FINST_C,
+                                 503, error_message(s, HTTP_ERR_503));
        else /* SI_ET_CONN_OTHER and others */
-               srv_close_with_err(s, SN_ERR_INTERNAL, SN_FINST_C,
-                                  500, error_message(s, HTTP_ERR_500));
+               http_server_error(s, si, SN_ERR_INTERNAL, SN_FINST_C,
+                                 500, error_message(s, HTTP_ERR_500));
 }
 
 extern const char sess_term_cond[8];