]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] make the http server error function a pointer in the session
authorWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 19:44:17 +0000 (20:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 19:44:17 +0000 (20:44 +0100)
It was a bit awkward to have session.c call return_srv_error() for
HTTP error messages related to servers. The function has been adapted
to be passed a pointer to the faulty stream interface, and is now a
pointer in the session. It is possible that in the future, it will
become a callback in the stream interface itself.

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

index 3addf3f2523c5b7bf3f4b8ae16318cee449e8058..72a5e3cc0770f6d2d47a14c00956d2334c0c3c81 100644 (file)
@@ -84,7 +84,7 @@ int http_find_header2(const char *name, int len,
                      struct hdr_ctx *ctx);
 void http_sess_log(struct session *s);
 void perform_http_redirect(struct session *s, struct stream_interface *si);
-void return_srv_error(struct session *s, int err_type);
+void http_return_srv_error(struct session *s, struct stream_interface *si);
 
 #endif /* _PROTO_PROTO_HTTP_H */
 
index 92bfa0626dbc06cb706c93ff82f77a325f7725d8..83d0a455f7df45bd5c8fed555cc912f9de82d6c0 100644 (file)
@@ -188,7 +188,9 @@ struct session {
                long long bytes_in;             /* number of bytes transferred from the client to the server */
                long long bytes_out;            /* number of bytes transferred from the server to the client */
        } logs;
-       void (*do_log)(struct session *s);      /* the function to call in order to log */
+       void (*do_log)(struct session *s);      /* the function to call in order to log (or NULL) */
+       void (*srv_error)(struct session *s,    /* the function to call upon unrecoverable server errors (or NULL) */
+                         struct stream_interface *si);
        short int data_source;                  /* where to get the data we generate ourselves */
        short int data_state;                   /* where to get the data we generate ourselves */
        union {
index bc7b2547eaf5f4fc3dcbeaa3c490962d5b5344de..bf7f55c7e8f717d77322f9b38bf8bab9f7ff7bf2 100644 (file)
@@ -212,6 +212,11 @@ int event_accept(int fd) {
                else
                        s->do_log = tcp_sess_log;
 
+               if (p->mode == PR_MODE_HTTP)
+                       s->srv_error = http_return_srv_error;
+               else
+                       s->srv_error = NULL;
+
                s->logs.accept_date = date; /* user-visible date for logging */
                s->logs.tv_accept = now;  /* corrected date for internal use */
                tv_zero(&s->logs.tv_request);
index 3991e41e85015d91268d8fea082598a9d2666b42..b52607675e3f89944462d1f3deaf38bc256bc8e9 100644 (file)
@@ -696,7 +696,7 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
                s->srv->cum_sess++;
 }
 
-/* Return the error message corresponding to err_type. It is assumed
+/* Return the error message corresponding to si->err_type. It is assumed
  * that the server side is closed. Note that err_type is actually a
  * bitmask, where almost only aborts may be cumulated with other
  * values. We consider that aborted operations are more important
@@ -705,9 +705,9 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
  * being cumulated. It should normally not be possible to have multiple
  * aborts at once, but just in case, the first one in sequence is reported.
  */
-void return_srv_error(struct session *s, int err_type)
+void http_return_srv_error(struct session *s, struct stream_interface *si)
 {
-       struct stream_interface *si = &s->si[1];
+       int err_type = si->err_type;
 
        if (err_type & SI_ET_QUEUE_ABRT)
                http_server_error(s, si, SN_ERR_CLICL, SN_FINST_Q,
index 1eb7b69fc5e43d0655273f6ad0ef7f6a8f9f7663..0550de1a4c1193683cf0a7ffe804089c17102bb4 100644 (file)
@@ -246,7 +246,8 @@ int sess_update_st_cer(struct session *s, struct stream_interface *si)
                si->ib->flags |= BF_READ_ERROR;
 
                si->state = SI_ST_CLO;
-               return_srv_error(s, si->err_type);
+               if (s->srv_error)
+                       s->srv_error(s, si);
                return 0;
        }
 
@@ -397,7 +398,8 @@ void sess_update_stream_int(struct session *s, struct stream_interface *si)
 
                        /* no session was ever accounted for this server */
                        si->state = SI_ST_CLO;
-                       return_srv_error(s, si->err_type);
+                       if (s->srv_error)
+                               s->srv_error(s, si);
                        return;
                }
 
@@ -443,7 +445,8 @@ void sess_update_stream_int(struct session *s, struct stream_interface *si)
                        if (!si->err_type)
                                si->err_type = SI_ET_QUEUE_TO;
                        si->state = SI_ST_CLO;
-                       return_srv_error(s, si->err_type);
+                       if (s->srv_error)
+                               s->srv_error(s, si);
                        return;
                }
 
@@ -458,7 +461,8 @@ void sess_update_stream_int(struct session *s, struct stream_interface *si)
                        si->shutw(si);
                        si->err_type |= SI_ET_QUEUE_ABRT;
                        si->state = SI_ST_CLO;
-                       return_srv_error(s, si->err_type);
+                       if (s->srv_error)
+                               s->srv_error(s, si);
                        return;
                }
 
@@ -476,7 +480,8 @@ void sess_update_stream_int(struct session *s, struct stream_interface *si)
                        si->shutw(si);
                        si->err_type |= SI_ET_CONN_ABRT;
                        si->state = SI_ST_CLO;
-                       return_srv_error(s, si->err_type);
+                       if (s->srv_error)
+                               s->srv_error(s, si);
                        return;
                }
 
@@ -529,7 +534,8 @@ static void sess_prepare_conn_req(struct session *s, struct stream_interface *si
                if (!si->err_type)
                        si->err_type = SI_ET_CONN_OTHER;
                si->state = SI_ST_CLO;
-               return_srv_error(s, si->err_type);
+               if (s->srv_error)
+                       s->srv_error(s, si);
                return;
        }