mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-02-06 01:41:53 +01:00
This commit implements a very simple HTTP Client API.
A client can be operated by several functions:
- httpclient_new(), httpclient_destroy(): create
and destroy the struct httpclient instance.
- httpclient_req_gen(): generate a complete HTX request using the
the absolute URL, the method and a list of headers. This request
is complete and sets the HTX End of Message flag. This is limited
to small request we don't need a body.
- httpclient_start() fill a sockaddr storage with a IP extracted
from the URL (it cannot resolve an fqdm for now), start the
applet. It also stores the ptr of the caller which could be an
appctx or something else.
- hc->ops contains a list of callbacks used by the
HTTPClient, they should be filled manually after an
httpclient_new():
* res_stline(): the client received a start line, its content
will be stored in hc->res.vsn, hc->res.status, hc->res.reason
* res_headers(): the client received headers, they are stored in
hc->res.hdrs.
* res_payload(): the client received some payload data, they are
stored in the hc->res.buf buffer and could be extracted with the
httpclient_res_xfer() function, which takes a destination buffer
as a parameter
* res_end(): this callback is called once we finished to receive
the response.
43 lines
1.3 KiB
C
43 lines
1.3 KiB
C
#ifndef _HAPROXY_HTTPCLIENT_T_H
|
|
#define _HAPROXY_HTTPCLIENT_T_H
|
|
|
|
#include <haproxy/http-t.h>
|
|
|
|
struct httpclient {
|
|
struct {
|
|
struct ist url; /* URL of the request */
|
|
enum http_meth_t meth; /* method of the request */
|
|
struct buffer buf; /* output buffer */
|
|
} req;
|
|
struct {
|
|
struct ist vsn;
|
|
uint16_t status;
|
|
struct ist reason;
|
|
struct http_hdr *hdrs; /* headers */
|
|
struct buffer buf; /* input buffer */
|
|
} res;
|
|
struct {
|
|
/* callbacks used to receive the response, if not set, the IO
|
|
* handler will consume the data without doing anything */
|
|
void (*res_stline)(struct httpclient *hc); /* start line received */
|
|
void (*res_headers)(struct httpclient *hc); /* headers received */
|
|
void (*res_payload)(struct httpclient *hc); /* payload received */
|
|
void (*res_end)(struct httpclient *hc); /* end of the response */
|
|
} ops;
|
|
struct sockaddr_storage dst; /* destination address */
|
|
struct appctx *appctx; /* HTTPclient appctx */
|
|
void *caller; /* ptr of the caller */
|
|
};
|
|
|
|
/* States of the HTTP Client Appctx */
|
|
enum {
|
|
HTTPCLIENT_S_REQ = 0,
|
|
HTTPCLIENT_S_RES_STLINE,
|
|
HTTPCLIENT_S_RES_HDR,
|
|
HTTPCLIENT_S_RES_BODY,
|
|
HTTPCLIENT_S_RES_END,
|
|
};
|
|
|
|
|
|
#endif /* ! _HAPROXY_HTTCLIENT__T_H */
|