From 92b27fd6159db986acdfdf172f694d0a7f45eae2 Mon Sep 17 00:00:00 2001 From: Ben Pirt Date: Thu, 5 Mar 2015 11:06:02 +0000 Subject: [PATCH] Expose the request type to the CGI functions so we can act based on its value --- user/httpd.c | 14 ++++++++++++-- user/httpd.h | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/user/httpd.c b/user/httpd.c index a5d924f..b0a741c 100644 --- a/user/httpd.c +++ b/user/httpd.c @@ -319,8 +319,18 @@ static void ICACHE_FLASH_ATTR httpdSendResp(HttpdConnData *conn) { //Parse a line of header data and modify the connection data accordingly. static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) { int i; -// os_printf("Got header %s\n", h); - if (os_strncmp(h, "GET ", 4)==0 || os_strncmp(h, "POST ", 5)==0) { + char first_line = false; + // os_printf("Got header %s\n", h); + + if (os_strncmp(h, "GET ", 4)==0){ + conn->requestType = GET; + first_line = true; + }else if(os_strncmp(h, "POST ", 5)==0) { + conn->requestType = POST; + first_line = true; + } + + if(first_line){ char *e; //Skip past the space after POST/GET diff --git a/user/httpd.h b/user/httpd.h index 0e929c4..8efd9b3 100644 --- a/user/httpd.h +++ b/user/httpd.h @@ -11,6 +11,9 @@ #define HTTPD_CGI_NOTFOUND 2 #define HTTPD_CGI_AUTHENTICATED 2 //for now +#define GET 1 +#define POST 2 + typedef struct HttpdPriv HttpdPriv; typedef struct HttpdConnData HttpdConnData; @@ -19,6 +22,7 @@ typedef int (* cgiSendCallback)(HttpdConnData *connData); //A struct describing a http connection. This gets passed to cgi functions. struct HttpdConnData { struct espconn *conn; + char requestType; char *url; char *getArgs; const void *cgiArg;