http: client POST method

Type: improvement

Change-Id: Iaa70abcee02866f9a6426a6e8e4709eeba0e8114
Signed-off-by: Matus Fabian <matfabia@cisco.com>
This commit is contained in:
Matus Fabian
2024-07-31 16:08:40 +02:00
committed by Florin Coras
parent fc3464dac9
commit d46e674abc
8 changed files with 885 additions and 62 deletions
+143 -10
View File
@@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptrace"
"os"
"strconv"
"sync"
"time"
@@ -27,9 +28,10 @@ func init() {
HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest,
HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest,
HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest,
HttpHeadersTest, HttpStaticFileHandler, HttpClientTest, HttpClientErrRespTest)
RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest, PromConcurrentConnections,
PromMemLeakTest)
HttpHeadersTest, HttpStaticFileHandlerTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest,
HttpClientPostFileTest, HttpClientPostFilePtrTest)
RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest, PromConcurrentConnectionsTest,
PromMemLeakTest, HttpClientPostMemLeakTest)
}
const wwwRootPath = "/tmp/www_root"
@@ -46,6 +48,7 @@ func httpDownloadBenchmark(s *HstSuite, experiment *gmeasure.Experiment, data in
defer resp.Body.Close()
s.AssertEqual(200, resp.StatusCode)
_, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
duration := time.Since(t)
experiment.RecordValue("Download Speed", (float64(resp.ContentLength)/1024/1024)/duration.Seconds(), gmeasure.Units("MB/s"), gmeasure.Precision(2))
}
@@ -114,7 +117,6 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) {
body, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
s.AssertEqual(string(body), "some data")
s.AssertNil(err, fmt.Sprint(err))
o2 := vpp.Vppctl("show session verbose proto http state ready")
s.Log(o2)
s.AssertContains(o2, "ESTABLISHED")
@@ -196,6 +198,7 @@ func HttpClientTest(s *NoTopoSuite) {
server.HTTPTestServer.Listener = l
server.AppendHandlers(
ghttp.CombineHandlers(
s.LogHttpReq(true),
ghttp.VerifyRequest("GET", "/test"),
ghttp.VerifyHeader(http.Header{"User-Agent": []string{"http_cli_client"}}),
ghttp.VerifyHeader(http.Header{"Accept": []string{"text / html"}}),
@@ -220,6 +223,7 @@ func HttpClientErrRespTest(s *NoTopoSuite) {
server.HTTPTestServer.Listener = l
server.AppendHandlers(
ghttp.CombineHandlers(
s.LogHttpReq(true),
ghttp.VerifyRequest("GET", "/test"),
ghttp.RespondWith(http.StatusNotFound, "404: Not Found"),
))
@@ -233,6 +237,74 @@ func HttpClientErrRespTest(s *NoTopoSuite) {
s.AssertContains(o, "404: Not Found", "error not found in the result!")
}
func HttpClientPostFormTest(s *NoTopoSuite) {
serverAddress := s.GetInterfaceByName(TapInterfaceName).Ip4AddressString()
body := "field1=value1&field2=value2"
server := ghttp.NewUnstartedServer()
l, err := net.Listen("tcp", serverAddress+":80")
s.AssertNil(err, fmt.Sprint(err))
server.HTTPTestServer.Listener = l
server.AppendHandlers(
ghttp.CombineHandlers(
s.LogHttpReq(true),
ghttp.VerifyRequest("POST", "/test"),
ghttp.VerifyContentType("application / x-www-form-urlencoded"),
ghttp.VerifyBody([]byte(body)),
ghttp.RespondWith(http.StatusOK, nil),
))
server.Start()
defer server.Close()
uri := "http://" + serverAddress + "/80"
vpp := s.GetContainerByName("vpp").VppInstance
o := vpp.Vppctl("http post uri " + uri + " target /test data " + body)
s.Log(o)
s.AssertNotContains(o, "error")
}
func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) {
serverAddress := s.GetInterfaceByName(TapInterfaceName).Ip4AddressString()
vpp := s.GetContainerByName("vpp").VppInstance
fileName := "/tmp/test_file.txt"
s.Log(vpp.Container.Exec("fallocate -l " + strconv.Itoa(fileSize) + " " + fileName))
s.Log(vpp.Container.Exec("ls -la " + fileName))
server := ghttp.NewUnstartedServer()
l, err := net.Listen("tcp", serverAddress+":80")
s.AssertNil(err, fmt.Sprint(err))
server.HTTPTestServer.Listener = l
server.AppendHandlers(
ghttp.CombineHandlers(
s.LogHttpReq(false),
ghttp.VerifyRequest("POST", "/test"),
ghttp.VerifyHeader(http.Header{"Content-Length": []string{strconv.Itoa(fileSize)}}),
ghttp.VerifyContentType("application / octet - stream"),
ghttp.RespondWith(http.StatusOK, nil),
))
server.Start()
defer server.Close()
uri := "http://" + serverAddress + "/80"
cmd := "http post uri " + uri + " target /test file " + fileName
if usePtr {
cmd += " use-ptr"
}
o := vpp.Vppctl(cmd)
s.Log(o)
s.AssertNotContains(o, "error")
}
func HttpClientPostFileTest(s *NoTopoSuite) {
httpClientPostFile(s, false, 32768)
}
func HttpClientPostFilePtrTest(s *NoTopoSuite) {
httpClientPostFile(s, true, 131072)
}
func HttpStaticPromTest(s *NoTopoSuite) {
query := "stats.prom"
vpp := s.GetContainerByName("vpp").VppInstance
@@ -252,6 +324,7 @@ func HttpStaticPromTest(s *NoTopoSuite) {
s.AssertContains(resp.Header.Get("Content-Type"), "plain")
s.AssertNotEqual(int64(0), resp.ContentLength)
_, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
}
func promReq(s *NoTopoSuite, url string) {
@@ -263,6 +336,7 @@ func promReq(s *NoTopoSuite, url string) {
defer resp.Body.Close()
s.AssertEqual(200, resp.StatusCode)
_, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
}
func promReqWg(s *NoTopoSuite, url string, wg *sync.WaitGroup) {
@@ -271,7 +345,7 @@ func promReqWg(s *NoTopoSuite, url string, wg *sync.WaitGroup) {
promReq(s, url)
}
func PromConcurrentConnections(s *NoTopoSuite) {
func PromConcurrentConnectionsTest(s *NoTopoSuite) {
vpp := s.GetContainerByName("vpp").VppInstance
serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
url := "http://" + serverAddress + ":80/stats.prom"
@@ -341,6 +415,9 @@ func HttpClientGetMemLeakTest(s *VethsSuite) {
/* warmup request (FIB) */
clientContainer.Vppctl("http cli client uri " + uri + " query /show/version")
/* let's give it some time to clean up sessions, so local port can be reused and we have less noise */
time.Sleep(time.Second * 12)
clientContainer.EnableMemoryTrace()
traces1, err := clientContainer.GetMemoryTrace()
s.AssertNil(err, fmt.Sprint(err))
@@ -355,13 +432,64 @@ func HttpClientGetMemLeakTest(s *VethsSuite) {
clientContainer.MemLeakCheck(traces1, traces2)
}
func HttpStaticFileHandler(s *NoTopoSuite) {
func HttpClientPostMemLeakTest(s *NoTopoSuite) {
s.SkipUnlessLeakCheck()
serverAddress := s.GetInterfaceByName(TapInterfaceName).Ip4AddressString()
body := "field1=value1&field2=value2"
uri := "http://" + serverAddress + "/80"
vpp := s.GetContainerByName("vpp").VppInstance
/* no goVPP less noise */
vpp.Disconnect()
server := ghttp.NewUnstartedServer()
l, err := net.Listen("tcp", serverAddress+":80")
s.AssertNil(err, fmt.Sprint(err))
server.HTTPTestServer.Listener = l
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/test"),
ghttp.RespondWith(http.StatusOK, nil),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/test"),
ghttp.RespondWith(http.StatusOK, nil),
),
)
server.Start()
defer server.Close()
/* warmup request (FIB) */
vpp.Vppctl("http post uri " + uri + " target /test data " + body)
/* let's give it some time to clean up sessions, so local port can be reused and we have less noise */
time.Sleep(time.Second * 12)
vpp.EnableMemoryTrace()
traces1, err := vpp.GetMemoryTrace()
s.AssertNil(err, fmt.Sprint(err))
vpp.Vppctl("http post uri " + uri + " target /test data " + body)
/* let's give it some time to clean up sessions */
time.Sleep(time.Second * 12)
traces2, err := vpp.GetMemoryTrace()
s.AssertNil(err, fmt.Sprint(err))
vpp.MemLeakCheck(traces1, traces2)
}
func HttpStaticFileHandlerTest(s *NoTopoSuite) {
content := "<html><body><p>Hello</p></body></html>"
content2 := "<html><body><p>Page</p></body></html>"
vpp := s.GetContainerByName("vpp").VppInstance
vpp.Container.Exec("mkdir -p " + wwwRootPath)
vpp.Container.CreateFile(wwwRootPath+"/index.html", content)
vpp.Container.CreateFile(wwwRootPath+"/page.html", content2)
err := vpp.Container.CreateFile(wwwRootPath+"/index.html", content)
s.AssertNil(err, fmt.Sprint(err))
err = vpp.Container.CreateFile(wwwRootPath+"/page.html", content2)
s.AssertNil(err, fmt.Sprint(err))
serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug cache-size 2m"))
@@ -377,6 +505,7 @@ func HttpStaticFileHandler(s *NoTopoSuite) {
s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=")
s.AssertEqual(int64(len([]rune(content))), resp.ContentLength)
body, err := io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
s.AssertEqual(string(body), content)
o := vpp.Vppctl("show http static server cache verbose")
s.Log(o)
@@ -392,6 +521,7 @@ func HttpStaticFileHandler(s *NoTopoSuite) {
s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=")
s.AssertEqual(int64(len([]rune(content))), resp.ContentLength)
body, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
s.AssertEqual(string(body), content)
req, err = http.NewRequest("GET", "http://"+serverAddress+":80/page.html", nil)
@@ -405,6 +535,7 @@ func HttpStaticFileHandler(s *NoTopoSuite) {
s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=")
s.AssertEqual(int64(len([]rune(content2))), resp.ContentLength)
body, err = io.ReadAll(resp.Body)
s.AssertNil(err, fmt.Sprint(err))
s.AssertEqual(string(body), content2)
o = vpp.Vppctl("show http static server cache verbose")
s.Log(o)
@@ -416,7 +547,8 @@ func HttpStaticPathTraversalTest(s *NoTopoSuite) {
vpp := s.GetContainerByName("vpp").VppInstance
vpp.Container.Exec("mkdir -p " + wwwRootPath)
vpp.Container.Exec("mkdir -p " + "/tmp/secret_folder")
vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret")
err := vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret")
s.AssertNil(err, fmt.Sprint(err))
serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug"))
@@ -436,7 +568,8 @@ func HttpStaticPathTraversalTest(s *NoTopoSuite) {
func HttpStaticMovedTest(s *NoTopoSuite) {
vpp := s.GetContainerByName("vpp").VppInstance
vpp.Container.Exec("mkdir -p " + wwwRootPath + "/tmp.aaa")
vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "<html><body><p>Hello</p></body></html>")
err := vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "<html><body><p>Hello</p></body></html>")
s.AssertNil(err, fmt.Sprint(err))
serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString()
s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug"))
+19 -1
View File
@@ -7,6 +7,8 @@ import (
"fmt"
"io"
"log"
"net/http"
"net/http/httputil"
"os"
"os/exec"
"path/filepath"
@@ -561,7 +563,7 @@ func (s *HstSuite) StartWget(finished chan error, server_ip, port, query, netNs
}
/*
runBenchmark creates Gomega's experiment with the passed-in name and samples the passed-in callback repeatedly (samplesNum times),
RunBenchmark creates Gomega's experiment with the passed-in name and samples the passed-in callback repeatedly (samplesNum times),
passing in suite context, experiment and your data.
You can also instruct runBenchmark to run with multiple concurrent workers.
@@ -578,3 +580,19 @@ func (s *HstSuite) RunBenchmark(name string, samplesNum, parallelNum int, callba
}, gmeasure.SamplingConfig{N: samplesNum, NumParallel: parallelNum})
AddReportEntry(experiment.Name, experiment)
}
/*
LogHttpReq is Gomega's ghttp server handler which logs received HTTP request.
You should put it at the first place, so request is logged always.
*/
func (s *HstSuite) LogHttpReq(body bool) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
dump, err := httputil.DumpRequest(req, body)
if err == nil {
s.Log("\n> Received request (" + req.RemoteAddr + "):\n" +
string(dump) +
"\n------------------------------\n")
}
}
}
+1
View File
@@ -21,6 +21,7 @@ add_vpp_plugin(hs_apps
hs_apps.c
http_cli.c
http_client_cli.c
http_simple_post.c
http_tps.c
proxy.c
test_builtins.c
File diff suppressed because it is too large Load Diff
+119 -47
View File
@@ -385,10 +385,16 @@ static const char *http_response_template = "HTTP/1.1 %s\r\n"
/**
* http request boilerplate
*/
static const char *http_request_template = "GET %s HTTP/1.1\r\n"
"Host: %v\r\n"
"User-Agent: %v\r\n"
"%s";
static const char *http_get_request_template = "GET %s HTTP/1.1\r\n"
"Host: %v\r\n"
"User-Agent: %v\r\n"
"%s";
static const char *http_post_request_template = "POST %s HTTP/1.1\r\n"
"Host: %v\r\n"
"User-Agent: %v\r\n"
"Content-Length: %u\r\n"
"%s";
static u32
http_send_data (http_conn_t *hc, u8 *data, u32 length, u32 offset)
@@ -1134,9 +1140,11 @@ http_state_wait_app_method (http_conn_t *hc, transport_send_params_t *sp)
{
http_msg_t msg;
session_t *as;
u8 *target = 0, *request;
u8 *target_buff = 0, *request = 0, *target;
u32 offset;
int rv;
http_sm_result_t sm_result = HTTP_SM_ERROR;
http_state_t next_state;
as = session_get_from_handle (hc->h_pa_session_handle);
@@ -1155,47 +1163,107 @@ http_state_wait_app_method (http_conn_t *hc, transport_send_params_t *sp)
goto error;
}
/* currently we support only GET method */
if (msg.method_type != HTTP_REQ_GET)
/* read request target */
if (msg.data.type == HTTP_MSG_DATA_PTR)
{
uword target_ptr;
rv = svm_fifo_dequeue (as->tx_fifo, sizeof (target_ptr),
(u8 *) &target_ptr);
ASSERT (rv == sizeof (target_ptr));
target = uword_to_pointer (target_ptr, u8 *);
}
else
{
vec_validate (target_buff, msg.data.target_path_len - 1);
rv =
svm_fifo_dequeue (as->tx_fifo, msg.data.target_path_len, target_buff);
ASSERT (rv == msg.data.target_path_len);
target = target_buff;
}
/* currently we support only GET and POST method */
if (msg.method_type == HTTP_REQ_GET)
{
if (msg.data.body_len)
{
clib_warning ("GET request shouldn't include data");
goto error;
}
/*
* Add "protocol layer" headers:
* - host
* - user agent
*/
request = format (0, http_get_request_template,
/* target */
target,
/* Host */
hc->host,
/* User-Agent */
hc->app_name,
/* Any headers from app? */
msg.data.headers_len ? "" : "\r\n");
next_state = HTTP_STATE_WAIT_SERVER_REPLY;
sm_result = HTTP_SM_STOP;
}
else if (msg.method_type == HTTP_REQ_POST)
{
if (!msg.data.body_len)
{
clib_warning ("POST request should include data");
goto error;
}
/*
* Add "protocol layer" headers:
* - host
* - user agent
* - content length
*/
request = format (0, http_post_request_template,
/* target */
target,
/* Host */
hc->host,
/* User-Agent */
hc->app_name,
/* Content-Length */
msg.data.body_len,
/* Any headers from app? */
msg.data.headers_len ? "" : "\r\n");
http_buffer_init (&hc->tx_buf, msg_to_buf_type[msg.data.type],
as->tx_fifo, msg.data.body_len);
next_state = HTTP_STATE_APP_IO_MORE_DATA;
sm_result = HTTP_SM_CONTINUE;
}
else
{
clib_warning ("unsupported method %d", msg.method_type);
goto error;
}
if (msg.data.body_len != 0)
{
clib_warning ("GET request shouldn't include data");
goto error;
}
/* read request target */
vec_validate (target, msg.data.target_path_len - 1);
rv = svm_fifo_dequeue (as->tx_fifo, msg.data.target_path_len, target);
ASSERT (rv == msg.data.target_path_len);
/*
* Add "protocol layer" headers:
* - host
* - user agent
*/
request = format (0, http_request_template,
/* target */
target,
/* Host */
hc->host,
/* User-Agent*/
hc->app_name,
/* Any headers from app? */
msg.data.headers_len ? "" : "\r\n");
/* Add headers from app (if any) */
if (msg.data.headers_len)
{
HTTP_DBG (0, "get headers from app, len %d", msg.data.headers_len);
u32 orig_len = vec_len (request);
vec_resize (request, msg.data.headers_len);
u8 *p = request + orig_len;
rv = svm_fifo_dequeue (as->tx_fifo, msg.data.headers_len, p);
ASSERT (rv == msg.data.headers_len);
HTTP_DBG (0, "got headers from app, len %d", msg.data.headers_len);
if (msg.data.type == HTTP_MSG_DATA_PTR)
{
uword app_headers_ptr;
rv = svm_fifo_dequeue (as->tx_fifo, sizeof (app_headers_ptr),
(u8 *) &app_headers_ptr);
ASSERT (rv == sizeof (app_headers_ptr));
vec_append (request, uword_to_pointer (app_headers_ptr, u8 *));
}
else
{
u32 orig_len = vec_len (request);
vec_resize (request, msg.data.headers_len);
u8 *p = request + orig_len;
rv = svm_fifo_dequeue (as->tx_fifo, msg.data.headers_len, p);
ASSERT (rv == msg.data.headers_len);
}
}
HTTP_DBG (0, "%v", request);
@@ -1203,22 +1271,23 @@ http_state_wait_app_method (http_conn_t *hc, transport_send_params_t *sp)
if (offset != vec_len (request))
{
clib_warning ("sending request failed!");
sm_result = HTTP_SM_ERROR;
goto error;
}
http_state_change (hc, HTTP_STATE_WAIT_SERVER_REPLY);
vec_free (target);
vec_free (request);
return HTTP_SM_STOP;
http_state_change (hc, next_state);
goto done;
error:
svm_fifo_dequeue_drop_all (as->tx_fifo);
session_transport_closing_notify (&hc->connection);
session_transport_closed_notify (&hc->connection);
http_disconnect_transport (hc);
return HTTP_SM_ERROR;
done:
vec_free (target_buff);
vec_free (request);
return sm_result;
}
static http_sm_result_t
@@ -1334,8 +1403,11 @@ http_state_app_io_more_data (http_conn_t *hc, transport_send_params_t *sp)
if (sent && svm_fifo_set_event (ts->tx_fifo))
session_program_tx_io_evt (ts->handle, SESSION_IO_EVT_TX_FLUSH);
/* Finished transaction, back to HTTP_STATE_WAIT_METHOD */
http_state_change (hc, HTTP_STATE_WAIT_CLIENT_METHOD);
/* Finished transaction:
* server back to HTTP_STATE_WAIT_METHOD
* client to HTTP_STATE_WAIT_SERVER_REPLY */
http_state_change (hc, hc->is_server ? HTTP_STATE_WAIT_CLIENT_METHOD :
HTTP_STATE_WAIT_SERVER_REPLY);
http_buffer_free (&hc->tx_buf);
}
+2
View File
@@ -132,6 +132,8 @@ typedef enum http_target_form_
_ (APP_XSLX, ".xlsx", \
"application / vnd.openxmlformats - officedocument.spreadsheetml.sheet") \
_ (APP_XUL, ".xul", "application / vnd.mozilla.xul + xml") \
_ (APP_X_WWW_FORM_URLENCODED, ".invalid", \
"application / x-www-form-urlencoded") \
_ (APP_ZIP, ".zip", "application / zip") \
_ (AUDIO_AAC, ".aac", "audio / aac") \
_ (AUDIO_CD, ".cda", "application / x - cdf") \
+1 -1
View File
@@ -173,7 +173,7 @@ buf_ptr_drain (http_buffer_t *hb, u32 len)
bf->segs[1].data += len;
bf->segs[0].len -= len;
HTTP_DBG (1, "drained %u left %u", len, bf->segs[1].len);
HTTP_DBG (1, "drained %u left %u", len, bf->segs[0].len);
if (!bf->segs[0].len)
{
+31 -3
View File
@@ -9,14 +9,14 @@ Overview
--------
This plugin adds the HTTP protocol to VPP's Host Stack.
As a result parsing of HTTP/1 request or response is available for internal VPP applications.
As a result parsing and serializing of HTTP/1 requests or responses are available for internal VPP applications.
Usage
-----
The plugin exposes following inline functions: ``http_validate_abs_path_syntax``, ``http_validate_query_syntax``,
``http_percent_decode``, ``http_path_remove_dot_segments``, ``http_parse_headers``, ``http_get_header``,
``http_free_header_table``.
``http_free_header_table``, ``http_add_header``, ``http_serialize_headers``.
It relies on the hoststack constructs and uses ``http_msg_data_t`` data structure for passing metadata to/from applications.
@@ -238,12 +238,18 @@ Finally application sends response body:
if (svm_fifo_set_event (ts->tx_fifo))
session_program_tx_io_evt (ts->handle, SESSION_IO_EVT_TX);
Example above shows how to send body data by copy, alternatively you could pass it as pointer:
Examples above shows how to send body and headers by copy, alternatively you could pass them as pointer:
.. code-block:: C
msg.data.type = HTTP_MSG_DATA_PTR;
/* code omitted for brevity */
if (msg.data.headers_len)
{
uword headers = pointer_to_uword (headers_buf);
rv = svm_fifo_enqueue (ts->tx_fifo, sizeof (headers), (u8 *) &headers);
ASSERT (rv == sizeof (headers));
}
uword data = pointer_to_uword (tx_buf);
rv = svm_fifo_enqueue (ts->tx_fifo, sizeof (data), (u8 *) &data);
ASSERT (rv == sizeof (data));
@@ -332,6 +338,28 @@ Finally application sends everything to HTTP layer:
if (svm_fifo_set_event (as->tx_fifo))
session_program_tx_io_evt (as->handle, SESSION_IO_EVT_TX);
Examples above shows how to send buffers by copy, alternatively you could pass them as pointer:
.. code-block:: C
msg.data.type = HTTP_MSG_DATA_PTR;
msg.method_type = HTTP_REQ_POST;
msg.data.body_len = vec_len (data);
/* code omitted for brevity */
uword target = pointer_to_uword (target);
uword headers = pointer_to_uword (headers_buf);
uword body = pointer_to_uword (data);
svm_fifo_seg_t segs[4] = {
{ (u8 *) &msg, sizeof (msg) },
{ (u8 *) &target, sizeof (target) },
{ (u8 *) &headers, sizeof (headers) },
{ (u8 *) &body, sizeof (body) },
};
rv = svm_fifo_enqueue_segments (s->tx_fifo, segs, 4, 0 /* allow partial */);
ASSERT (rv == (sizeof (msg) + sizeof (target) + sizeof (headers) + sizeof (body)));
In this case you need to free data when you receive response or when session is closed.
Receiving data
""""""""""""""