int i;
int foundhost = 0, foundaccept = 0, foundua = 0;
+ if (!b_alloc(&hc->req.buf))
+ goto error;
+
if (meth >= HTTP_METH_OTHER)
goto error;
ret = b_force_xfer(dst, &hc->res.buf, MIN(1024, b_data(&hc->res.buf)));
/* call the client once we consumed all data */
- if (!b_data(&hc->res.buf) && hc->appctx)
- appctx_wakeup(hc->appctx);
+ if (!b_data(&hc->res.buf)) {
+ b_free(&hc->res.buf);
+ if (hc->appctx)
+ appctx_wakeup(hc->appctx);
+ }
return ret;
}
int ret = 0;
struct htx *htx;
+ if (!b_alloc(&hc->req.buf))
+ goto error;
+
htx = htx_from_buf(&hc->req.buf);
if (!htx)
goto error;
struct httpclient *httpclient_new(void *caller, enum http_meth_t meth, struct ist url)
{
struct httpclient *hc;
- struct buffer *b;
hc = calloc(1, sizeof(*hc));
if (!hc)
goto err;
- b = b_alloc(&hc->req.buf);
- if (!b)
- goto err;
- b = b_alloc(&hc->res.buf);
- if (!b)
- goto err;
-
+ hc->req.buf = BUF_NULL;
+ hc->res.buf = BUF_NULL;
hc->caller = caller;
hc->req.url = istdup(url);
hc->req.meth = meth;
if (!ret)
goto more;
+ if (!b_data(&hc->req.buf))
+ b_free(&hc->req.buf);
+
htx = htx_from_buf(&req->buf);
if (!htx)
goto more;
ret = b_xfer(&req->buf, &hc->req.buf, b_data(&hc->req.buf));
if (!ret)
goto more;
+
+ if (!b_data(&hc->req.buf))
+ b_free(&hc->req.buf);
+
htx = htx_from_buf(&req->buf);
if (!htx)
goto more;
if (!htx || htx_is_empty(htx))
goto more;
+ if (!b_alloc(&hc->res.buf))
+ goto more;
+
if (b_full(&hc->res.buf))
- goto process_data;
+ goto process_data;
/* decapsule the htx data to raw data */
for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {