MINOR: http-ana: Rely on http_reply_and_close() to handle server error

The http_server_error() function now relies on http_reply_and_close(). Both do
almost the same actions. In addtion, http_server_error() sets the error flag and
the final state flag on the stream.
This commit is contained in:
Christopher Faulet 2020-01-27 15:32:25 +01:00
parent 60b33a5a62
commit 72c7d8d040
2 changed files with 7 additions and 32 deletions

View File

@ -48,7 +48,7 @@ void http_check_request_for_cacheability(struct stream *s, struct channel *req);
void http_check_response_for_cacheability(struct stream *s, struct channel *res);
void http_perform_server_redirect(struct stream *s, struct stream_interface *si);
void http_server_error(struct stream *s, struct stream_interface *si, int err, int finst, const struct buffer *msg);
void http_reply_and_close(struct stream *s, short status, struct buffer *msg);
void http_reply_and_close(struct stream *s, short status, const struct buffer *msg);
void http_return_srv_error(struct stream *s, struct stream_interface *si);
struct buffer *http_error_message(struct stream *s);

View File

@ -4550,45 +4550,25 @@ static void http_end_response(struct stream *s)
void http_server_error(struct stream *s, struct stream_interface *si, int err,
int finst, const struct buffer *msg)
{
channel_auto_read(si_oc(si));
channel_abort(si_oc(si));
channel_auto_close(si_oc(si));
channel_htx_erase(si_oc(si), htxbuf(&(si_oc(si))->buf));
channel_htx_truncate(si_ic(si), htxbuf(&(si_ic(si))->buf));
channel_auto_close(si_ic(si));
channel_auto_read(si_ic(si));
/* <msg> is an HTX structure. So we copy it in the response's
* channel */
if (msg && !b_is_null(msg)) {
struct channel *chn = si_ic(si);
struct htx *htx;
size_t data;
FLT_STRM_CB(s, flt_http_reply(s, s->txn->status, msg));
htx = htx_from_buf(&chn->buf);
if (channel_htx_copy_msg(chn, htx, msg)) {
htx->flags |= HTX_FL_PROXY_RESP;
data = htx->data - co_data(chn);
c_adv(chn, data);
htx->first = -1;
chn->total += data;
}
}
http_reply_and_close(s, s->txn->status, msg);
if (!(s->flags & SF_ERR_MASK))
s->flags |= err;
if (!(s->flags & SF_FINST_MASK))
s->flags |= finst;
}
void http_reply_and_close(struct stream *s, short status, struct buffer *msg)
void http_reply_and_close(struct stream *s, short status, const struct buffer *msg)
{
channel_auto_read(&s->req);
channel_abort(&s->req);
channel_auto_close(&s->req);
channel_htx_erase(&s->req, htxbuf(&s->req.buf));
channel_htx_truncate(&s->res, htxbuf(&s->res.buf));
channel_auto_read(&s->res);
channel_auto_close(&s->res);
channel_shutr_now(&s->res);
s->res.wex = tick_add_ifset(now_ms, s->res.wto);
s->txn->flags &= ~TX_WAIT_NEXT_RQ;
/* <msg> is an HTX structure. So we copy it in the response's
@ -4608,11 +4588,6 @@ void http_reply_and_close(struct stream *s, short status, struct buffer *msg)
chn->total += data;
}
}
s->res.wex = tick_add_ifset(now_ms, s->res.wto);
channel_auto_read(&s->res);
channel_auto_close(&s->res);
channel_shutr_now(&s->res);
}
struct buffer *http_error_message(struct stream *s)