X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/15f84bb8f5b910de40f081ee5e8ed847c592ea17..c6f21fde628193c7957d84792215ecaa14d5beb7:/Projects/Webserver/Lib/HTTPServerApp.c diff --git a/Projects/Webserver/Lib/HTTPServerApp.c b/Projects/Webserver/Lib/HTTPServerApp.c index c2263cb98..0d0cbb903 100644 --- a/Projects/Webserver/Lib/HTTPServerApp.c +++ b/Projects/Webserver/Lib/HTTPServerApp.c @@ -31,7 +31,7 @@ /** \file * * Simple HTTP Webserver Application. When connected to the uIP stack, - * this will serve out files to HTTP clients. + * this will serve out files to HTTP clients on port 80. */ #define INCLUDE_FROM_HTTPSERVERAPP_C @@ -40,27 +40,27 @@ /** HTTP server response header, for transmission before the page contents. This indicates to the host that a page exists at the * given location, and gives extra connection information. */ -char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n" - "Server: LUFA RNDIS\r\n" - "Connection: close\r\n" - "MIME-version: 1.0\r\n" - "Content-Type: "; +const char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n" + "Server: LUFA " LUFA_VERSION_STRING "\r\n" + "Connection: close\r\n" + "MIME-version: 1.0\r\n" + "Content-Type: "; /** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given * given URL is invalid, and gives extra error information. */ -char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" - "Server: LUFA RNDIS\r\n" - "Connection: close\r\n" - "MIME-version: 1.0\r\n" - "Content-Type: text/plain\r\n\r\n" - "Error 404: File Not Found"; +const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" + "Server: LUFA " LUFA_VERSION_STRING "\r\n" + "Connection: close\r\n" + "MIME-version: 1.0\r\n" + "Content-Type: text/plain\r\n\r\n" + "Error 404: File Not Found"; -/** Default MIME type sent if no other MIME type can be determined */ -char PROGMEM DefaultMIMEType[] = "text/plain"; +/** Default MIME type sent if no other MIME type can be determined. */ +const char PROGMEM DefaultMIMEType[] = "text/plain"; /** List of MIME types for each supported file extension. */ -MIME_Type_t PROGMEM MIMETypes[] = +const MIME_Type_t MIMETypes[] = { {.Extension = "htm", .MIMEType = "text/html"}, {.Extension = "jpg", .MIMEType = "image/jpeg"}, @@ -198,7 +198,7 @@ static void HTTPServerApp_SendResponseHeader(void) uip_tcp_appstate_t* const AppState = &uip_conn->appstate; char* const AppData = (char*)uip_appdata; - char* HeaderToSend; + const char* HeaderToSend; /* Determine which HTTP header should be sent to the client */ if (AppState->HTTPServer.FileOpen) @@ -234,10 +234,10 @@ static void HTTPServerApp_SendMIMETypeHeader(void) /* Look through the MIME type list, copy over the required MIME type if found */ for (int i = 0; i < (sizeof(MIMETypes) / sizeof(MIMETypes[0])); i++) { - if (strcmp_P(&Extension[1], MIMETypes[i].Extension) == 0) + if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0) { - MIMEHeaderLength = strlen_P(MIMETypes[i].MIMEType); - strncpy_P(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength); + MIMEHeaderLength = strlen(MIMETypes[i].MIMEType); + strncpy(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength); break; } } @@ -270,8 +270,12 @@ static void HTTPServerApp_SendData(void) uip_tcp_appstate_t* const AppState = &uip_conn->appstate; char* const AppData = (char*)uip_appdata; - /* Must determine the maximum segment size to determine maximum file chunk size */ - uint16_t MaxSegmentSize = uip_mss(); + /* Must determine the maximum segment size to determine maximum file chunk size - never send a completely + * full packet, as this will cause some hosts to start delaying ACKs until a non-full packet is received. + * since uIP only allows one packet to be in transit at a time, this would cause long delays between packets + * until the host times out and sends the ACK for the last received packet. + */ + uint16_t MaxSegmentSize = (uip_mss() >> 1); /* Return file pointer to the last ACKed position */ f_lseek(&AppState->HTTPServer.FileHandle, AppState->HTTPServer.ACKedFilePos);