You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/23 18:28:32 UTC
[incubator-nuttx-apps] branch master updated: netutils/webclient:
Notify HTTP header data via dedicated callback
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new a1026c9 netutils/webclient: Notify HTTP header data via dedicated callback
a1026c9 is described below
commit a1026c9f23450abeb4611a23f7c7c09370054b55
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Jul 21 12:05:18 2021 -0300
netutils/webclient: Notify HTTP header data via dedicated callback
Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
include/netutils/webclient.h | 20 +++++++++++++++++++-
netutils/webclient/webclient.c | 16 ++++++++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/include/netutils/webclient.h b/include/netutils/webclient.h
index 77b7e19..5f5c8ce 100644
--- a/include/netutils/webclient.h
+++ b/include/netutils/webclient.h
@@ -47,6 +47,8 @@
****************************************************************************/
#include <nuttx/config.h>
+
+#include <stdbool.h>
#include <sys/types.h>
/****************************************************************************
@@ -103,7 +105,7 @@
typedef void (*wget_callback_t)(FAR char **buffer, int offset,
int datend, FAR int *buflen, FAR void *arg);
-/* webclient_sink_callback_t: callback to consume data
+/* webclient_sink_callback_t: callback to consume body data
*
* Same as wget_callback_t, but allowed to fail.
*
@@ -119,6 +121,20 @@ typedef CODE int (*webclient_sink_callback_t)(FAR char **buffer, int offset,
int datend, FAR int *buflen,
FAR void *arg);
+/* webclient_header_callback_t: callback to consume header data
+ *
+ * Input Parameters:
+ * line - A NULL-terminated string containing a header line.
+ * truncated - Flag for indicating whether the received header line is
+ * truncated for exceeding the CONFIG_WEBCLIENT_MAXHTTPLINE
+ * length limit.
+ * arg - User argument passed to callback.
+ */
+
+typedef CODE int (*webclient_header_callback_t)(FAR const char *line,
+ bool truncated,
+ FAR void *arg);
+
/* webclient_body_callback_t: a callback to provide request body
*
* This callback can be called multiple times to provide
@@ -239,6 +255,8 @@ struct webclient_context
wget_callback_t callback;
webclient_sink_callback_t sink_callback;
FAR void *sink_callback_arg;
+ webclient_header_callback_t header_callback;
+ FAR void *header_callback_arg;
webclient_body_callback_t body_callback;
FAR void *body_callback_arg;
FAR const struct webclient_tls_ops *tls_ops;
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 8a64b26..19d66ee 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -519,7 +519,8 @@ static int parseurl(FAR const char *url, FAR struct wget_s *ws)
* Name: wget_parseheaders
****************************************************************************/
-static inline int wget_parseheaders(struct wget_s *ws)
+static inline int wget_parseheaders(struct webclient_context *ctx,
+ struct wget_s *ws)
{
int offset;
int ndx;
@@ -559,6 +560,7 @@ static inline int wget_parseheaders(struct wget_s *ws)
ninfo("Got HTTP header line%s: %.*s\n",
got_nl ? "" : " (truncated)",
ndx - 1, &ws->line[0]);
+
if (ws->line[0] == ISO_CR)
{
/* This was the last header line (i.e., and empty "\r\n"),
@@ -597,6 +599,16 @@ static inline int wget_parseheaders(struct wget_s *ws)
return -EPROTO;
}
+ if (ctx->header_callback)
+ {
+ ret = ctx->header_callback(&ws->line[0], !got_nl,
+ ctx->header_callback_arg);
+ if (ret != 0)
+ {
+ goto exit;
+ }
+ }
+
/* Check for specific HTTP header fields. */
#ifdef CONFIG_WEBCLIENT_GETMIMETYPE
@@ -1046,7 +1058,7 @@ int webclient_perform(FAR struct webclient_context *ctx)
if (ws->state == WEBCLIENT_STATE_HEADERS)
{
- ret = wget_parseheaders(ws);
+ ret = wget_parseheaders(ctx, ws);
if (ret < 0)
{
goto errout_with_errno;