[En-Nut-Discussion] httpd with dynamically generated text orbinary files

Hugo Simon hugo.simon at gmx.de
Sat Oct 22 15:29:18 CEST 2005


> That has nothing to do with this at all.
It has to do with it. The NutHttpProcessRequest checks if the CGI URL points
to a file in cgi-bin. All other file requests are routed to urom:

> Your are telling that content length is '%ld' and browser doesn't
That indeed was a mistake. I copied too much. :-)
The new version simply give no content length or a valid one. But that
wasn't the problem, the browser ignores that wrong parameter anyway.

The problem is, that the NutProcessCGIRequest function only allows GET and
PUT method. HEAD is simply dropped and gave an error 501. Internet Explorer
doesn't have a problem with that, but Mozilla had.

So I created a new set of functions called NutRegisterFile,
NutProcessFileRequest, ...
These functions work exactly as the CGI functions, except that it looks for
files in the path _proc_ and does not drop the HEAD method. So now I can
register a file in that _proc_ "directory" to a function like I did in CGIs.

The user function has to check if there is the HEAD function or not and then
my drop the content generation like shown below:


int LoadBinaryFile(FILE *stream, REQUEST *req)
{
 long i;
 printf("LoadBinary Method = %i, %s\n",req->req_method,req->req_url);
  NutHttpSendHeaderTop(stream, req, 200, "Ok");
  NutHttpSendHeaderBot(stream, "application/octet-stream", 256);
  if (req->req_method != METHOD_HEAD)
  {
    for (i=0;i<256;i++) fputc(i,stream);
  }
 fflush(stream);
  return 0;
}


In main:

  NutRegisterFile("mess.bin", LoadBinaryFile);


In Website:

<p><a href="_proc_/mess.bin">load binary file</a></p>

Thanks anyway,

bye
Thorsten




More information about the En-Nut-Discussion mailing list