From patch attached to nuttx/ Bitbucket Issue #136 from Vlado Vidovic:

The patch provided in issue 135, which adds support for HTTP Chunked Encoding, covers all paths in the webserver app except CGI callbacks. As a result, if a page being served happens to use CGI, it could generate stream content that does not comply with HTTP Chunked Encoding.

The patch attached amends the webserver app's CGI callbacks to use the HTTP Chunked Encoding sender function instead of using send() directly.
This commit is contained in:
Gregory Nutt 2018-11-23 17:29:07 -06:00
parent d3c36663d0
commit e88a529010
3 changed files with 24 additions and 9 deletions

View File

@ -70,11 +70,17 @@ static void net_stats(struct httpd_state *pstate, char *ptr)
{
char buffer[16];
int i;
bool chunked_http_tx = 0;
#if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING)
chunked_http_tx = pstate->ht_chunked;
#endif
for (i = 0; i < sizeof(g_netstats) / sizeof(net_stats_t); i++)
{
snprintf(buffer, 16, "%5u\n", ((net_stats_t *)&g_netstats)[i]);
send(pstate->ht_sockfd, buffer, strlen(buffer), 0);
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
chunked_http_tx);
}
}
#endif
@ -88,8 +94,15 @@ static void file_stats(struct httpd_state *pstate, char *ptr)
{
char buffer[16];
char *pcount = strchr(ptr, ' ') + 1;
bool chunked_http_tx = 0;
#if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING)
chunked_http_tx = pstate->ht_chunked;
#endif
snprintf(buffer, 16, "%5u", httpd_fs_count(pcount));
send(pstate->ht_sockfd, buffer, strlen(buffer), 0);
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
chunked_http_tx);
}
#endif

View File

@ -1,7 +1,8 @@
/****************************************************************************
* apps/include/netutils/httpd.h
*
* Copyright (C) 2007, 2009, 2011-2012, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011-2012, 2014, 2018 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Based on uIP which also has a BSD style license:
@ -98,7 +99,7 @@
*/
#define HTTPD_MAX_CONTENTLEN 32
#define HTTPD_MAX_HEADERLEN 180
#define HTTPD_MAX_HEADERLEN 220
#define HTTPD_MAX_CHUNKEDLEN 16
/****************************************************************************
@ -109,7 +110,8 @@ struct httpd_fs_file
{
char *data;
int len;
#if defined(CONFIG_NETUTILS_HTTPD_MMAP) || defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
#if defined(CONFIG_NETUTILS_HTTPD_MMAP) || \
defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
int fd;
#endif
};
@ -166,8 +168,8 @@ struct httpd_cgi_call
*
* Description:
* This macro is used for declaring a HTTPD CGI function. This function is
* then added to the list of HTTPD CGI functions with the httpd_cgi_register()
* function.
* then added to the list of HTTPD CGI functions with the
* httpd_cgi_register() function.
* Input Parameters:
*
@ -203,6 +205,7 @@ void httpd_init(void);
int httpd_listen(void);
void httpd_cgi_register(struct httpd_cgi_call *cgi_call);
uint16_t httpd_fs_count(char *name);
int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked);
#undef EXTERN
#ifdef __cplusplus

View File

@ -212,8 +212,7 @@ static int httpd_close(struct httpd_fs_file *file)
*
****************************************************************************/
static int httpd_send_datachunk(int sockfd, void * data, int len,
bool chunked)
int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked)
{
int ret = 0;
#if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING)