You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
7.9 KiB

  1. From 2e47a3ab11188239abadb6bba7bd901d764aa4fb Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Tue, 30 Sep 2014 18:44:22 +0200
  4. Subject: [PATCH 16/20] BUG/MEDIUM: http: adjust close mode when switching to
  5. backend
  6. Commit 179085c ("MEDIUM: http: move Connection header processing earlier")
  7. introduced a regression : the backend's HTTP mode is not considered anymore
  8. when setting the session's HTTP mode, because wait_for_request() is only
  9. called once, when the frontend receives the request (or when the frontend
  10. is in TCP mode, when the backend receives the request).
  11. The net effect is that in some situations when the frontend and the backend
  12. do not work in the same mode (eg: keep-alive vs close), the backend's mode
  13. is ignored.
  14. This patch moves all that processing to a dedicated function, which is
  15. called from the original place, as well as from session_set_backend()
  16. when switching from an HTTP frontend to an HTTP backend in different
  17. modes.
  18. This fix must be backported to 1.5.
  19. (cherry picked from commit 4e21ff9244aefa56bcf0793a9e07edba2c3c1960)
  20. ---
  21. include/proto/proto_http.h | 1 +
  22. src/proto_http.c | 107 +++++++++++++++++++++++----------------------
  23. src/proxy.c | 8 ++++
  24. 3 files changed, 64 insertions(+), 52 deletions(-)
  25. diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
  26. index e898ca8..8014310 100644
  27. --- a/include/proto/proto_http.h
  28. +++ b/include/proto/proto_http.h
  29. @@ -112,6 +112,7 @@ unsigned int http_get_hdr(const struct http_msg *msg, const char *hname, int hle
  30. void http_init_txn(struct session *s);
  31. void http_end_txn(struct session *s);
  32. void http_reset_txn(struct session *s);
  33. +void http_adjust_conn_mode(struct session *s, struct http_txn *txn, struct http_msg *msg);
  34. struct http_req_rule *parse_http_req_cond(const char **args, const char *file, int linenum, struct proxy *proxy);
  35. struct http_res_rule *parse_http_res_cond(const char **args, const char *file, int linenum, struct proxy *proxy);
  36. diff --git a/src/proto_http.c b/src/proto_http.c
  37. index 7e35c8b..20e7088 100644
  38. --- a/src/proto_http.c
  39. +++ b/src/proto_http.c
  40. @@ -2393,6 +2393,59 @@ fail:
  41. return 0;
  42. }
  43. +void http_adjust_conn_mode(struct session *s, struct http_txn *txn, struct http_msg *msg)
  44. +{
  45. + int tmp = TX_CON_WANT_KAL;
  46. +
  47. + if (!((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
  48. + if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN ||
  49. + (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
  50. + tmp = TX_CON_WANT_TUN;
  51. +
  52. + if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
  53. + (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
  54. + tmp = TX_CON_WANT_TUN;
  55. + }
  56. +
  57. + if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
  58. + (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) {
  59. + /* option httpclose + server_close => forceclose */
  60. + if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
  61. + (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
  62. + tmp = TX_CON_WANT_CLO;
  63. + else
  64. + tmp = TX_CON_WANT_SCL;
  65. + }
  66. +
  67. + if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL ||
  68. + (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
  69. + tmp = TX_CON_WANT_CLO;
  70. +
  71. + if ((txn->flags & TX_CON_WANT_MSK) < tmp)
  72. + txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | tmp;
  73. +
  74. + if (!(txn->flags & TX_HDR_CONN_PRS) &&
  75. + (txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) {
  76. + /* parse the Connection header and possibly clean it */
  77. + int to_del = 0;
  78. + if ((msg->flags & HTTP_MSGF_VER_11) ||
  79. + ((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL &&
  80. + !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)))
  81. + to_del |= 2; /* remove "keep-alive" */
  82. + if (!(msg->flags & HTTP_MSGF_VER_11))
  83. + to_del |= 1; /* remove "close" */
  84. + http_parse_connection_header(txn, msg, to_del);
  85. + }
  86. +
  87. + /* check if client or config asks for explicit close in KAL/SCL */
  88. + if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL ||
  89. + (txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL) &&
  90. + ((txn->flags & TX_HDR_CONN_CLO) || /* "connection: close" */
  91. + (!(msg->flags & HTTP_MSGF_VER_11) && !(txn->flags & TX_HDR_CONN_KAL)) || /* no "connection: k-a" in 1.0 */
  92. + !(msg->flags & HTTP_MSGF_XFER_LEN) || /* no length known => close */
  93. + s->fe->state == PR_STSTOPPED)) /* frontend is stopping */
  94. + txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
  95. +}
  96. /* This stream analyser waits for a complete HTTP request. It returns 1 if the
  97. * processing can continue on next analysers, or zero if it either needs more
  98. @@ -2929,58 +2982,8 @@ int http_wait_for_request(struct session *s, struct channel *req, int an_bit)
  99. * time.
  100. */
  101. if (!(txn->flags & TX_HDR_CONN_PRS) ||
  102. - ((s->fe->options & PR_O_HTTP_MODE) != (s->be->options & PR_O_HTTP_MODE))) {
  103. - int tmp = TX_CON_WANT_KAL;
  104. -
  105. - if (!((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
  106. - if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN ||
  107. - (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
  108. - tmp = TX_CON_WANT_TUN;
  109. -
  110. - if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
  111. - (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
  112. - tmp = TX_CON_WANT_TUN;
  113. - }
  114. -
  115. - if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
  116. - (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) {
  117. - /* option httpclose + server_close => forceclose */
  118. - if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
  119. - (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
  120. - tmp = TX_CON_WANT_CLO;
  121. - else
  122. - tmp = TX_CON_WANT_SCL;
  123. - }
  124. -
  125. - if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL ||
  126. - (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
  127. - tmp = TX_CON_WANT_CLO;
  128. -
  129. - if ((txn->flags & TX_CON_WANT_MSK) < tmp)
  130. - txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | tmp;
  131. -
  132. - if (!(txn->flags & TX_HDR_CONN_PRS) &&
  133. - (txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) {
  134. - /* parse the Connection header and possibly clean it */
  135. - int to_del = 0;
  136. - if ((msg->flags & HTTP_MSGF_VER_11) ||
  137. - ((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL &&
  138. - !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)))
  139. - to_del |= 2; /* remove "keep-alive" */
  140. - if (!(msg->flags & HTTP_MSGF_VER_11))
  141. - to_del |= 1; /* remove "close" */
  142. - http_parse_connection_header(txn, msg, to_del);
  143. - }
  144. -
  145. - /* check if client or config asks for explicit close in KAL/SCL */
  146. - if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL ||
  147. - (txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL) &&
  148. - ((txn->flags & TX_HDR_CONN_CLO) || /* "connection: close" */
  149. - (!(msg->flags & HTTP_MSGF_VER_11) && !(txn->flags & TX_HDR_CONN_KAL)) || /* no "connection: k-a" in 1.0 */
  150. - !(msg->flags & HTTP_MSGF_XFER_LEN) || /* no length known => close */
  151. - s->fe->state == PR_STSTOPPED)) /* frontend is stopping */
  152. - txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
  153. - }
  154. + ((s->fe->options & PR_O_HTTP_MODE) != (s->be->options & PR_O_HTTP_MODE)))
  155. + http_adjust_conn_mode(s, txn, msg);
  156. /* end of job, return OK */
  157. req->analysers &= ~an_bit;
  158. diff --git a/src/proxy.c b/src/proxy.c
  159. index 02103ee..405c4c4 100644
  160. --- a/src/proxy.c
  161. +++ b/src/proxy.c
  162. @@ -955,6 +955,14 @@ int session_set_backend(struct session *s, struct proxy *be)
  163. http_init_txn(s);
  164. }
  165. + /* If we chain to an HTTP backend running a different HTTP mode, we
  166. + * have to re-adjust the desired keep-alive/close mode to accommodate
  167. + * both the frontend's and the backend's modes.
  168. + */
  169. + if (s->fe->mode == PR_MODE_HTTP && be->mode == PR_MODE_HTTP &&
  170. + ((s->fe->options & PR_O_HTTP_MODE) != (be->options & PR_O_HTTP_MODE)))
  171. + http_adjust_conn_mode(s, &s->txn, &s->txn.req);
  172. +
  173. /* If an LB algorithm needs to access some pre-parsed body contents,
  174. * we must not start to forward anything until the connection is
  175. * confirmed otherwise we'll lose the pointer to these data and
  176. --
  177. 2.0.4