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.

80 lines
3.6 KiB

  1. From 0cb4b899d370b9d04b3457a1d75dbd658c1a1646 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Tue, 16 Sep 2014 10:40:38 +0200
  4. Subject: [PATCH 06/13] MEDIUM: http: enable header manipulation for 101
  5. responses
  6. Ryan Brock reported that server stickiness did not work for WebSocket
  7. because the cookies and headers are not modified on 1xx responses. He
  8. found that his browser correctly presents the cookies learned on 101
  9. responses, which was not specifically defined in the WebSocket spec,
  10. nor in the cookie spec. 101 is a very special case. Being part of 1xx,
  11. it's an interim response. But within 1xx, it's special because it's
  12. the last HTTP/1 response that transits on the wire, which is different
  13. from 100 or 102 which may appear multiple times. So in that sense, we
  14. can consider it as a final response regarding HTTP/1, and it makes
  15. sense to allow header processing there. Note that we still ensure not
  16. to mangle the Connection header, which is critical for HTTP upgrade to
  17. continue to work smoothly with agents that are a bit picky about what
  18. tokens are found there.
  19. The rspadd rules are now processed for 101 responses as well, but the
  20. cache-control checks are not performed (since no body is delivered).
  21. Ryan confirmed that this patch works for him.
  22. It would make sense to backport it to 1.5 given that it improves end
  23. user experience on WebSocket servers.
  24. (cherry picked from commit ce730de86719d0b5079dd8b0843559e4ff0a1ecc)
  25. ---
  26. src/proto_http.c | 12 +++++++-----
  27. 1 file changed, 7 insertions(+), 5 deletions(-)
  28. diff --git a/src/proto_http.c b/src/proto_http.c
  29. index 4d27b2c..7e35c8b 100644
  30. --- a/src/proto_http.c
  31. +++ b/src/proto_http.c
  32. @@ -6249,7 +6249,7 @@ int http_process_res_common(struct session *s, struct channel *rep, int an_bit,
  33. /* add response headers from the rule sets in the same order */
  34. list_for_each_entry(wl, &rule_set->rsp_add, list) {
  35. - if (txn->status < 200)
  36. + if (txn->status < 200 && txn->status != 101)
  37. break;
  38. if (wl->cond) {
  39. int ret = acl_exec_cond(wl->cond, px, s, txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
  40. @@ -6270,7 +6270,7 @@ int http_process_res_common(struct session *s, struct channel *rep, int an_bit,
  41. }
  42. /* OK that's all we can do for 1xx responses */
  43. - if (unlikely(txn->status < 200))
  44. + if (unlikely(txn->status < 200 && txn->status != 101))
  45. goto skip_header_mangling;
  46. /*
  47. @@ -6283,7 +6283,7 @@ int http_process_res_common(struct session *s, struct channel *rep, int an_bit,
  48. /*
  49. * Check for cache-control or pragma headers if required.
  50. */
  51. - if ((s->be->options & PR_O_CHK_CACHE) || (s->be->ck_opts & PR_CK_NOC))
  52. + if (((s->be->options & PR_O_CHK_CACHE) || (s->be->ck_opts & PR_CK_NOC)) && txn->status != 101)
  53. check_response_for_cacheability(s, rep);
  54. /*
  55. @@ -6399,9 +6399,11 @@ int http_process_res_common(struct session *s, struct channel *rep, int an_bit,
  56. * Adjust "Connection: close" or "Connection: keep-alive" if needed.
  57. * If an "Upgrade" token is found, the header is left untouched in order
  58. * not to have to deal with some client bugs : some of them fail an upgrade
  59. - * if anything but "Upgrade" is present in the Connection header.
  60. + * if anything but "Upgrade" is present in the Connection header. We don't
  61. + * want to touch any 101 response either since it's switching to another
  62. + * protocol.
  63. */
  64. - if (!(txn->flags & TX_HDR_CONN_UPG) &&
  65. + if ((txn->status != 101) && !(txn->flags & TX_HDR_CONN_UPG) &&
  66. (((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) ||
  67. ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
  68. (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))) {
  69. --
  70. 1.8.5.5