.. js:function:: HTTPMessage.eom(http_msg)
This function returns true if the end of message is reached for the HTTP
- message **http_msg**.
+ message **http_msg**. When called by a filter, the result is relative to the
+ data visible by this filter: if an earlier filter holds back some data, the
+ function always returns false, even if the end of the message was received,
+ because the held data may still carry it.
:param class_httpmessage http_msg: The manipulated HTTP message.
- :returns: an integer containing the amount of available bytes.
+ :returns: a boolean
.. js:function:: HTTPMessage.del_header(http_msg, name)
.. js:function:: HTTPMessage.may_recv(http_msg)
This function returns true if the HTTP message **http_msg** may still receive
- data.
+ data. When called by a filter, the result is relative to the data visible by
+ this filter: if an earlier filter holds back some data, the function always
+ returns true, because the held data may still be exposed to the current
+ filter, even if nothing will be received anymore.
:param class_httpmessage http_msg: The manipulated HTTP message.
:returns: a boolean
return filter;
}
+/* Helper function to know if all data in an HTX message are visible.
+ * Returns 1 if no filter are attached to the HTTP message or if all HTX data are
+ * visible by the filter Otherwise 0 is returned. */
+static int hlua_http_msg_fully_visible(lua_State *L, struct http_msg *msg, struct htx *htx)
+{
+ size_t offset, len;
+
+ hlua_http_msg_filter(L, 1, msg, &offset, &len);
+ return (offset + len == htx->data);
+}
+
/* Returns true if the channel attached to the HTTP message is the response
* channel.
*/
{
struct http_msg *msg;
struct htx *htx;
+ int may_recv;
MAY_LJMP(check_args(L, 1, "may_recv"));
msg = MAY_LJMP(hlua_checkhttpmsg(L, 1));
htx = htxbuf(&msg->chn->buf);
- lua_pushboolean(L, (htx_expect_more(htx) && !channel_input_closed(msg->chn) && channel_may_recv(msg->chn)));
+ may_recv = !hlua_http_msg_fully_visible(L, msg, htx) || (htx_expect_more(htx) &&
+ !channel_input_closed(msg->chn) &&
+ channel_may_recv(msg->chn));
+
+ lua_pushboolean(L, may_recv);
return 1;
}
{
struct http_msg *msg;
struct htx *htx;
+ int eom;
- MAY_LJMP(check_args(L, 1, "may_recv"));
+ MAY_LJMP(check_args(L, 1, "eom"));
msg = MAY_LJMP(hlua_checkhttpmsg(L, 1));
htx = htxbuf(&msg->chn->buf);
- lua_pushboolean(L, !htx_expect_more(htx));
+ eom = hlua_http_msg_fully_visible(L, msg, htx) && htx_msg_ended(htx);
+ lua_pushboolean(L, eom);
return 1;
}