/** HTTP server response header, for transmission before the page contents. This indicates to the host that a page exists at the\r
* given location, and gives extra connection information.\r
*/\r
-char PROGMEM HTTPHeader[] = "HTTP/1.1 200 OK\r\n"\r
- "Server: LUFA RNDIS\r\n"\r
- "Content-type: text/html\r\n"\r
- "Connection: close\r\n\r\n";\r
+char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"\r
+ "Server: LUFA RNDIS\r\n"\r
+ "Content-type: text/html\r\n"\r
+ "Connection: close\r\n\r\n";\r
+ \r
+char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"\r
+ "Server: LUFA RNDIS\r\n"\r
+ "Connection: close\r\n\r\n";\r
\r
/** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically\r
* broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run.\r
\r
/** Indicates if a given request equals the given HTTP command.\r
*\r
- * \param RequestHeader HTTP request made by the host\r
- * \param Command HTTP command to compare the request to\r
+ * \param[in] RequestHeader HTTP request made by the host\r
+ * \param[in] Command HTTP command to compare the request to\r
*\r
* \return Boolean true if the command matches the request, false otherwise\r
*/\r
/** Application callback routine, executed each time the TCP processing task runs. This callback determines what request\r
* has been made (if any), and serves up appropriate responses.\r
*\r
- * \param ConnectionState Pointer to a TCP Connection State structure giving connection information\r
- * \param Buffer Pointer to the application's send/receive packet buffer\r
+ * \param[in] ConnectionState Pointer to a TCP Connection State structure giving connection information\r
+ * \param[in,out] Buffer Pointer to the application's send/receive packet buffer\r
*/\r
void Webserver_ApplicationCallback(TCP_ConnectionState_t* ConnectionState, TCP_ConnectionBuffer_t* Buffer)\r
{\r
{\r
if (IsHTTPCommand(Buffer->Data, "GET"))\r
{\r
- PageBlock = 0;\r
-\r
- /* Copy the HTTP response header into the packet buffer */\r
- strcpy_P(BufferDataStr, HTTPHeader);\r
- \r
- /* Send the buffer contents to the host */\r
- TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));\r
-\r
- /* Lock the buffer to Device->Host transmissions only while we send the page contents */\r
- TCP_APP_CAPTURE_BUFFER(Buffer);\r
+ if (IsHTTPCommand(Buffer->Data, "GET / "))\r
+ {\r
+ PageBlock = 0;\r
+\r
+ /* Copy the HTTP 200 response header into the packet buffer */\r
+ strcpy_P(BufferDataStr, HTTP200Header);\r
+ \r
+ /* Send the buffer contents to the host */\r
+ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));\r
+\r
+ /* Lock the buffer to Device->Host transmissions only while we send the page contents */\r
+ TCP_APP_CAPTURE_BUFFER(Buffer);\r
+ }\r
+ else\r
+ {\r
+ /* Copy the HTTP 404 response header into the packet buffer */\r
+ strcpy_P(BufferDataStr, HTTP404Header);\r
+ \r
+ /* Send the buffer contents to the host */\r
+ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));\r
+ \r
+ /* All data sent, close the connection */\r
+ TCP_APP_CLOSECONNECTION(ConnectionState);\r
+ }\r
}\r
else if (IsHTTPCommand(Buffer->Data, "HEAD"))\r
{\r
- /* Copy the HTTP response header into the packet buffer */\r
- strcpy_P(BufferDataStr, HTTPHeader);\r
-\r
- /* Send the buffer contents to the host */\r
- TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));\r
+ if (IsHTTPCommand(Buffer->Data, "HEAD / "))\r
+ {\r
+ /* Copy the HTTP response header into the packet buffer */\r
+ strcpy_P(BufferDataStr, HTTP200Header);\r
+\r
+ /* Send the buffer contents to the host */\r
+ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));\r
+ }\r
+ else\r
+ {\r
+ /* Copy the HTTP response header into the packet buffer */\r
+ strcpy_P(BufferDataStr, HTTP404Header);\r
+\r
+ /* Send the buffer contents to the host */\r
+ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr)); \r
+ }\r
+ \r
+ /* All data sent, close the connection */\r
+ TCP_APP_CLOSECONNECTION(ConnectionState);\r
}\r
else if (IsHTTPCommand(Buffer->Data, "TRACE"))\r
{\r
/* Echo the host's query back to the host */\r
TCP_APP_SEND_BUFFER(Buffer, Buffer->Length);\r
+ \r
+ /* All data sent, close the connection */\r
+ TCP_APP_CLOSECONNECTION(ConnectionState);\r
}\r
else\r
{\r