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.

48 lines
1.9 KiB

  1. commit 52131680c42ddbfa6f2b5d109ffc79c28f44e42a
  2. Author: Christopher Faulet <cfaulet@haproxy.com>
  3. Date: Thu Jun 27 17:40:14 2019 +0200
  4. BUG/MINOR: mux-h1: Skip trailers for non-chunked outgoing messages
  5. Unlike H1, H2 messages may contains trailers while the header "Content-Length"
  6. is set. Indeed, because of the framed structure of HTTP/2, it is no longer
  7. necessary to use the chunked transfer encoding. So Trailing HEADERS frames,
  8. after all DATA frames, may be added on messages with an explicit content length.
  9. But in H1, it is impossible to have trailers on non-chunked messages. So when
  10. outgoing messages are formatted by the H1 multiplexer, if the message is not
  11. chunked, all trailers must be dropped.
  12. This patch must be backported to 2.0 and 1.9. However, the patch will have to be
  13. adapted for the 1.9.
  14. (cherry picked from commit 5433a0b0215c791b4165bddd360a254fa141c6e9)
  15. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  16. diff --git a/src/mux_h1.c b/src/mux_h1.c
  17. index e497e6f6..e7d769b4 100644
  18. --- a/src/mux_h1.c
  19. +++ b/src/mux_h1.c
  20. @@ -1696,7 +1696,9 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
  21. goto done;
  22. }
  23. else if (type == HTX_BLK_EOT || type == HTX_BLK_TLR) {
  24. - if (!chunk_memcat(&tmp, "0\r\n", 3))
  25. + /* If the message is not chunked, never
  26. + * add the last chunk. */
  27. + if ((h1m->flags & H1_MF_CHNK) && !chunk_memcat(&tmp, "0\r\n", 3))
  28. goto copy;
  29. goto trailers;
  30. }
  31. @@ -1715,6 +1717,11 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
  32. goto error;
  33. trailers:
  34. h1m->state = H1_MSG_TRAILERS;
  35. + /* If the message is not chunked, ignore
  36. + * trailers. It may happen with H2 messages. */
  37. + if (!(h1m->flags & H1_MF_CHNK))
  38. + break;
  39. +
  40. if (type == HTX_BLK_EOT) {
  41. if (!chunk_memcat(&tmp, "\r\n", 2))
  42. goto copy;