MAJOR: http: reset msg->sov after headers are forwarded
In order to avoid abusively relying on buf->o to guess how many bytes to
rewind during a redispatch, we now clear msg->sov. Thus the meaning of this
field is exactly "how many bytes of headers are left to be forwarded". It
is still possible to rewind because msg->eoh + msg->eol equal that value
before scheduling the forwarding, so we can always subtract them.
diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h
index 53f0eca..2c8b062 100644
--- a/include/proto/proto_http.h
+++ b/include/proto/proto_http.h
@@ -134,10 +134,13 @@
/* Return the amount of bytes that need to be rewound before buf->p to access
* the current message's headers. The purpose is to be able to easily fetch
* the message's beginning before headers are forwarded, as well as after.
+ * The principle is that msg->eoh and msg->eol are immutable while msg->sov
+ * equals the sum of the two before forwarding and is zero after forwarding,
+ * so the difference cancels the rewinding.
*/
static inline int http_hdr_rewind(const struct http_msg *msg)
{
- return msg->chn->buf->o;
+ return msg->eoh + msg->eol - msg->sov;
}
/* Return the amount of bytes that need to be rewound before buf->p to access
@@ -179,7 +182,7 @@
{
int len;
- len = buffer_len(msg->chn->buf) - msg->sov - msg->sol;
+ len = msg->chn->buf->i - msg->sov - msg->sol;
if (len > msg->body_len)
len = msg->body_len;
return len;