]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: http: make http_server_error() not set the status anymore
authorWilly Tarreau <w@1wt.eu>
Tue, 14 Mar 2017 10:07:31 +0000 (11:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 Mar 2017 10:09:04 +0000 (11:09 +0100)
Given that all call places except one had to set txn->status prior to
calling http_server_error(), it's simpler to make this function rely
on txn->status than have it store it from an argument.

src/proto_http.c

index 7fed50e6515c8fb0abcb9108d77a5ec0ee5e0d98..c0f57c5210455d8c9dc200326f04bbb2fb6770f5 100644 (file)
@@ -1037,22 +1037,20 @@ int http_remove_header2(struct http_msg *msg, struct hdr_idx *idx, struct hdr_ct
 
 /* 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.
+ * message is copied into the input buffer.
  * The error flags are set to the values in arguments. Any pending request
  * in this buffer will be lost.
  */
 static void http_server_error(struct stream *s, struct stream_interface *si,
-                             int err, int finst, int status, const struct chunk *msg)
+                             int err, int finst, const struct chunk *msg)
 {
-       FLT_STRM_CB(s, flt_http_reply(s, status, msg));
+       FLT_STRM_CB(s, flt_http_reply(s, s->txn->status, msg));
        channel_auto_read(si_oc(si));
        channel_abort(si_oc(si));
        channel_auto_close(si_oc(si));
        channel_erase(si_oc(si));
        channel_auto_close(si_ic(si));
        channel_auto_read(si_ic(si));
-       if (status > 0)
-               s->txn->status = status;
        if (msg)
                bo_inject(si_ic(si), msg->str, msg->len);
        if (!(s->flags & SF_ERR_MASK))
@@ -1258,7 +1256,8 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
        si->state    = SI_ST_CLO;
 
        /* send the message */
-       http_server_error(s, si, SF_ERR_LOCAL, SF_FINST_C, 302, &trash);
+       txn->status = 302;
+       http_server_error(s, si, SF_ERR_LOCAL, SF_FINST_C, &trash);
 
        /* FIXME: we should increase a counter of redirects per server and per backend. */
        srv_inc_sess_ctr(srv);
@@ -1285,33 +1284,33 @@ void http_return_srv_error(struct stream *s, struct stream_interface *si)
 
        if (err_type & SI_ET_QUEUE_ABRT)
                http_server_error(s, si, SF_ERR_CLICL, SF_FINST_Q,
-                                 503, http_error_message(s));
+                                 http_error_message(s));
        else if (err_type & SI_ET_CONN_ABRT)
                http_server_error(s, si, SF_ERR_CLICL, SF_FINST_C,
-                                 503, (s->txn->flags & TX_NOT_FIRST) ? NULL :
+                                 (s->txn->flags & TX_NOT_FIRST) ? NULL :
                                  http_error_message(s));
        else if (err_type & SI_ET_QUEUE_TO)
                http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_Q,
-                                 503, http_error_message(s));
+                                 http_error_message(s));
        else if (err_type & SI_ET_QUEUE_ERR)
                http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_Q,
-                                 503, http_error_message(s));
+                                 http_error_message(s));
        else if (err_type & SI_ET_CONN_TO)
                http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_C,
-                                 503, (s->txn->flags & TX_NOT_FIRST) ? NULL :
+                                 (s->txn->flags & TX_NOT_FIRST) ? NULL :
                                  http_error_message(s));
        else if (err_type & SI_ET_CONN_ERR)
                http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_C,
-                                 503, (s->flags & SF_SRV_REUSED) ? NULL :
+                                 (s->flags & SF_SRV_REUSED) ? NULL :
                                  http_error_message(s));
        else if (err_type & SI_ET_CONN_RES)
                http_server_error(s, si, SF_ERR_RESOURCE, SF_FINST_C,
-                                 503, (s->txn->flags & TX_NOT_FIRST) ? NULL :
+                                 (s->txn->flags & TX_NOT_FIRST) ? NULL :
                                  http_error_message(s));
        else { /* SI_ET_CONN_OTHER and others */
                s->txn->status = 500;
                http_server_error(s, si, SF_ERR_INTERNAL, SF_FINST_C,
-                                 500, http_error_message(s));
+                                 http_error_message(s));
        }
 }