ソースの整理中ですが、利用はできます。

Dependencies:   EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Files at this revision

API Documentation at this revision

Comitter:
yueee_yt
Date:
Wed Mar 12 04:39:15 2014 +0000
Parent:
1:d403150d596c
Commit message:
bug fix

Changed in this revision

HttpServer/HTTPRequestHandler.cpp Show annotated file Show diff for this revision Revisions of this file
HttpServer/HTTPRequestHandler.h Show annotated file Show diff for this revision Revisions of this file
--- a/HttpServer/HTTPRequestHandler.cpp	Wed Mar 12 04:29:14 2014 +0000
+++ b/HttpServer/HTTPRequestHandler.cpp	Wed Mar 12 04:39:15 2014 +0000
@@ -175,8 +175,8 @@
     static char line[128];
     static char key[128];
     static char value[128];
-    int i;
     char *p;
+    chunkmode=false;
     req_headers_count=0;
     resp_headers_count=0;
     while( readLine(line, 128) > 0) { //if == 0, it is an empty line = end of headers
@@ -200,6 +200,11 @@
 #endif
             if(strcmp(key,"CONTENT-LENGTH")==0) {
                 sscanf(value,"%d",&clength);
+            } else if(strcmp(key,"TRANSFER-ENCODING")==0) {
+                for(p=&value[0]; p<(&value[0]+strlen(value)); p++) {
+                    if((*p>0x60)&&(*p<0x7b))*p=*p-0x20;
+                }
+                if(strcmp(value,"CHUNKED")==0)chunkmode=true;
             }
         }
         //TODO: Impl n==1 case (part 2 of previous header)
@@ -208,53 +213,26 @@
 
 void HTTPRequestHandler::readReqData()
 {
-    static char key[128];
-    static char value[128];
-    int cont_length=0;
-    bool chunk=false;
-    char *p;
     int i;
     //ReadHeader
-//    map< string, string >::iterator it;
-//    for (it = m_reqHeaders.begin(); it != m_reqHeaders.end(); it++) {
-    for (i=0; i<req_headers_count; i++) {
-//        sprintf(key,"%s",(*it).first.c_str());
-//        sprintf(value,"%s",(*it).second.c_str());
-        sprintf(key,"%s",req_headers_key[i].c_str());
-        sprintf(value,"%s",req_headers_value[i].c_str());
-        for(p=&key[0]; p<(&key[0]+strlen(key)); p++) {
-            if((*p>0x60)&&(*p<0x7b))*p=*p-0x20;
-        }
-#ifdef _DEBUG_REQUEST_SERVER_H
-        printf("+++(HTTPRequestHandler) HEADER %s\r\n",key);
-#endif
-        if(strcmp(key,"CONTENT-LENGTH")==0) {
-            sscanf(value,"%d",&cont_length);
-        } else if(strcmp(key,"TRANSFER-ENCODING")==0) {
-            for(p=&value[0]; p<(&value[0]+strlen(value)); p++) {
-                if((*p>0x60)&&(*p<0x7b))*p=*p-0x20;
-            }
-            if(strcmp(value,"CHUNKED")==0)chunk=true;
-        }
-    }
 #ifdef _DEBUG_REQUEST_SERVER_H
     printf("+++(HTTPRequestHandler)content-length: %d \r\n",cont_length);
-    if(chunk==true)printf("+++(HTTPRequestHandler)CHUNK Transfer \r\n");
+    if(chunkmode==true)printf("+++(HTTPRequestHandler)CHUNK Transfer \r\n");
     else printf("+++(HTTPRequestHandler)NO CHUNK Transfer \r\n");
 #endif
 //   m_pTCPSocketConnection->set_blocking(true,HTTP_POST_REQUEST_TIMEOUT);
     char buffer[READ_SIZE+1];
-    if(chunk==false) {
+    if(chunkmode==false) {
         //no chunked mode
         for(;;) {
-            if(cont_length>READ_SIZE) {
+            if(clength>READ_SIZE) {
                 i=m_pTCPSocketConnection->receive(buffer,READ_SIZE);
                 buffer[READ_SIZE]=0x0;
                 m_reqData.append(string(buffer));
-                cont_length-=READ_SIZE;
+                clength-=READ_SIZE;
             } else {
-                i=m_pTCPSocketConnection->receive(buffer, cont_length);
-                buffer[cont_length]=0x0;
+                i=m_pTCPSocketConnection->receive(buffer, clength);
+                buffer[clength]=0x0;
                 m_reqData.append(string(buffer));
                 break;
             }
--- a/HttpServer/HTTPRequestHandler.h	Wed Mar 12 04:29:14 2014 +0000
+++ b/HttpServer/HTTPRequestHandler.h	Wed Mar 12 04:39:15 2014 +0000
@@ -111,6 +111,7 @@
 
     int readLine(char* str, int maxLen);
 int clength;
+bool chunkmode;
 };
 
 #endif