http server design, POST method

Hi,
I want to know whether my coding logic below correctly implements http POST
method. Am I also correctly implementing CGI interface part of web server ?
Is CGI interface necessary for handling POST method(I think so) ?

pw is PrintWriter associated with socket's outputstream. Code is in Java,
but someone programming with other languages can also give useful comments.


public static void handlePOST(Http ht,String s)
{
     try {
       String rd1 = s.substring(0,s.indexOf('\n'));
       System.out.println(rd1);
       String filestr = rd1.substring(rd1.indexOf('/') + 1);
       String filename = filestr.substring(0,filestr.indexOf(' '));
       System.out.println(filename);
       File f = new File(filename);
       if (!f.exists())
       {
         ht.pw.println("<HTML>");
         ht.pw.flush();
         ht.pw.println("<H2>Object "+filename+" does not exist on the
server</H2>");
         ht.pw.flush();
         ht.pw.println("</HTML>");
         ht.pw.flush();
         socket.close();
       }
       else
       {
         //pass the file to CGI interface
         String[] cgiresponse = cgi_interface(filename);
         //send contents of cgiresponse string array to the PrintWriter
         //output stream i.e ht.pw
       }
     }
     catch(IOException ex)
     {
       ex.printStackTrace();
     }
  } //end of handlePOST method

  public String[] cgi_interface(String f)
  {
    //a. check for file extension
    //b. Read from configuration repository(e.g a file) application that
will run
    //   the file based on file extension
    //c. execute the application giving file as a parameter
    //d. store standard output from the application into a string array
    //e. return the string array to calling function
  } //end of cgi_interface method

-mukul

Received on Wednesday, 4 August 1999 07:40:20 UTC