uridecoding lws_hdr_fragment_length

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2016-01-20 09:37:42 +08:00
parent 0f8b1919ef
commit 00e5eb8658
2 changed files with 33 additions and 1 deletions

View file

@ -1555,11 +1555,25 @@ lws_b64_decode_string(const char *in, char *out, int out_size);
LWS_VISIBLE LWS_EXTERN const char *
lws_get_library_version(void);
/* access to headers... only valid while headers valid */
/*
* Access to http headers
*
* In lws the client http headers are temporarily malloc'd only for the
* duration of the http part of the handshake. It's because in most cases,
* the header content is ignored for the whole rest of the connection lifetime
* and would then just be taking up space needlessly.
*
* During LWS_CALLBACK_HTTP when the URI path is delivered is the last time
* the http headers are still allocated, you can use these apis then to
* look at and copy out interesting header content (cookies, etc)
*/
LWS_VISIBLE LWS_EXTERN int
lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
LWS_VISIBLE LWS_EXTERN int
lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
/*
* copies the whole, aggregated header, even if it was delivered in
* several actual headers piece by piece
@ -1576,6 +1590,7 @@ LWS_VISIBLE LWS_EXTERN int
lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
enum lws_token_indexes h, int frag_idx);
/* get the active file operations struct */
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
lws_get_fops(struct lws_context *context);

View file

@ -81,6 +81,23 @@ int lws_free_header_table(struct lws *wsi)
return 0;
};
LWS_VISIBLE int
lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx)
{
int n;
n = wsi->u.hdr.ah->frag_index[h];
if (!n)
return 0;
do {
if (!frag_idx)
return wsi->u.hdr.ah->frags[n].len;
n = wsi->u.hdr.ah->frags[n].nfrag;
} while (frag_idx-- && n);
return 0;
}
LWS_VISIBLE int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h)
{
int n;