From 25a09840800788132669a84c74db3de960996925 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Thu, 11 Dec 2014 20:33:53 +0100 Subject: [PATCH] Added httpdGetHeader function --- user/httpd.c | 28 ++++++++++++++++++++++++++++ user/httpd.h | 1 + 2 files changed, 29 insertions(+) diff --git a/user/httpd.c b/user/httpd.c index 43eb699..8da3f68 100644 --- a/user/httpd.c +++ b/user/httpd.c @@ -161,6 +161,34 @@ int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLe return -1; //not found } +//Get the value of a certain header in the HTTP client head +int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen) { + char *p=conn->priv->head; + p=p+strlen(p)+1; //skip GET/POST part + p=p+strlen(p)+1; //skip HTTP part + while (p<(conn->priv->head+conn->priv->headPos)) { + while(*p<=32 && *p!=0) p++; //skip crap at start +// os_printf("Looking for %s, Header: '%s'\n", header, p); + //See if this is the header + if (os_strncmp(p, header, strlen(header))==0 && p[strlen(header)]==':') { + //Skip 'key:' bit of header line + p=p+strlen(header)+1; + //Skip past spaces after the colon + while(*p==' ') p++; + //Copy from p to end + while (*p!=0 && *p!='\r' && *p!='\n' && retLen>1) { + *ret++=*p++; + retLen--; + } + //Zero-terminate string + *ret=0; + //All done :) + return 1; + } + p+=strlen(p)+1; //Skip past end of string and \0 terminator + } + return 0; +} //Start the response headers. void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) { diff --git a/user/httpd.h b/user/httpd.h index 724bd39..8cdab8d 100644 --- a/user/httpd.h +++ b/user/httpd.h @@ -45,5 +45,6 @@ const char *httpdGetMimetype(char *url); void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); +int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen); #endif \ No newline at end of file