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.

72 lines
2.2 KiB

  1. commit 54948f3fd310ffc74a6c252dc11046a8a18ab230
  2. Author: Jerome Magnin <jmagnin@haproxy.com>
  3. Date: Sat Nov 9 18:00:47 2019 +0100
  4. BUG/MINOR: stream: init variables when the list is empty
  5. We need to call vars_init() when the list is empty otherwise we
  6. can't use variables in the response scope. This regression was
  7. introduced by cda7f3f5 (MINOR: stream: don't prune variables if
  8. the list is empty).
  9. The following config reproduces the issue:
  10. defaults
  11. mode http
  12. frontend in
  13. bind *:11223
  14. http-request set-var(req.foo) str("foo") if { path /bar }
  15. http-request set-header bar %[var(req.foo)] if { var(req.foo) -m found }
  16. http-response set-var(res.bar) str("bar")
  17. http-response set-header foo %[var(res.bar)] if { var(res.bar) -m found }
  18. use_backend out
  19. backend out
  20. server s1 127.0.0.1:11224
  21. listen back
  22. bind *:11224
  23. http-request deny deny_status 200
  24. > GET /ba HTTP/1.1
  25. > Host: localhost:11223
  26. > User-Agent: curl/7.66.0
  27. > Accept: */*
  28. >
  29. < HTTP/1.0 200 OK
  30. < Cache-Control: no-cache
  31. < Content-Type: text/html
  32. > GET /bar HTTP/1.1
  33. > Host: localhost:11223
  34. > User-Agent: curl/7.66.0
  35. > Accept: */*
  36. >
  37. < HTTP/1.0 200 OK
  38. < Cache-Control: no-cache
  39. < Content-Type: text/html
  40. < foo: bar
  41. This must be backported as far as 1.9.
  42. (cherry picked from commit 2f44e8843a553ef0f9c53c9b27899727de097777)
  43. Signed-off-by: Willy Tarreau <w@1wt.eu>
  44. diff --git a/src/stream.c b/src/stream.c
  45. index 4a7ced22..9fe0efaf 100644
  46. --- a/src/stream.c
  47. +++ b/src/stream.c
  48. @@ -2399,10 +2399,9 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
  49. if (si_state_in(si_b->state, SI_SB_REQ|SI_SB_QUE|SI_SB_TAR|SI_SB_ASS)) {
  50. /* prune the request variables and swap to the response variables. */
  51. if (s->vars_reqres.scope != SCOPE_RES) {
  52. - if (!LIST_ISEMPTY(&s->vars_reqres.head)) {
  53. + if (!LIST_ISEMPTY(&s->vars_reqres.head))
  54. vars_prune(&s->vars_reqres, s->sess, s);
  55. - vars_init(&s->vars_reqres, SCOPE_RES);
  56. - }
  57. + vars_init(&s->vars_reqres, SCOPE_RES);
  58. }
  59. do {