Check to see if valid web server GET request?

I have this partially, working; however, it breaks the download from happening with “Page Not Found.”
Here I have it commented out to allow downloads to work.

/*         // pageNotFound 404
         if (!( StrContains(HTTP_req, "GET / ")) || ( StrContains(HTTP_req, "GET /log.txt "))){
           
         // send a standard http response header
              client.println("HTTP/1.1 404");
              client.println("Content-Type: text/html");
              client.println("Connnection: close");
              client.println();
              // output webpage
              client.println("<!DOCTYPE HTML>");
              client.println("<html>\r\n");
              client.println("<h2>Page Not Found</h2>
");    
              client.println("<html>\r\n");
        
         // reset buffer index and all buffer elements to 0
              req_index = 0;
              StrClear(HTTP_req, REQ_BUF_SZ);
           
              break;      
              }
*/

I am expecting “Page Not Found” for any invalid request; this part is working.

What is missing or wrong?

Complete code attached to topic:.

Topic_CC3000_Weather_Observations_Webserver.zip (6.66 KB)

Did you mean to have one negative and one positive clause in your if statement? Perhaps you're missing a set of parens?

Did you mean to have one negative and one positive clause in your if statement? Perhaps you're missing a set of parens?

I am trying to negate, two clauses that are sperated by OR. Is the syntax correct to accomplish this task?

This is for a web server to check for invaild GET requests. Anything other than (StrContains(HTTP_req, "GET / ")) || (StrContains(HTTP_req, "GET /log.txt ")) will result in a "Page Not Found" exception.

Is there a better way to go about coding this task?

Is there a better way to go about coding this task?

In my opinion, yes.

if(StrContains(HTTP_req, "GET / "))
{
   // Return the base page
}
else if(StrContains(HTTP_req, "GET /log.txt"))
{
   // Return the log file
}
else
{
   // Return the error page
}

Deal with the valid requests, first. Then, anything that’s left is an invalid request.

Deal with the valid requests, first. Then, anything that’s left is an invalid request.

Thank you PaulS.

I have it working now. Here is what worked; had to add the additional code here…

else if ((!StrContains(HTTP_req, "GET / "))||(!StrContains(HTTP_req, "GET /log.txt"))){

Appreciate the reply .

William

CC3000_Weather_Observations_Webserver.zip (6.5 KB)