[En-Nut-Discussion] httpd with dynamically generated text or binary files
Vesa Jääskeläinen
chaac at nic.fi
Sat Oct 22 12:45:33 CEST 2005
Hugo Simon wrote:
> Hi,
>
> I want to create a webserver application where a user can download text or
> binary files which does not lay in the ROM filessystem but are generated on
> the fly from some data the nut has collected.
>
> First approach was to use NutHttpProcessRequest() and register a CGI which
> generates the file. It works if the user clicks the link to the file but
> didn't work if he choose to "save destination to file". Why?
See below.
> I think it has something to do with that the "file" have to be in cgi-bin.
> Ist there a way to register a normal URL to a function?
That has nothing to do with this at all.
> Here is the function to create a file via CGI:
>
> int LoadASCIIFile(FILE *stream, REQUEST *req)
> {
> fputs_P(PSTR("HTTP/1.0 200 OK\r\n"
> "Server: shServer\r\n" "Content-Length: %ld\r\n"
> "Connection: close\r\n\r\n"),stream);
Your are telling that content length is '%ld' and browser doesn't
understand this at all. So basicly you are instructing client with wrong
information. Check out HTTP 1.0 or newer specification for details how
HTTP protocol works.
HTTP 1.0 (RFC-1945):
ftp://ftp.rfc-editor.org/in-notes/rfc1945.txt
HTTP 1.1 (RFC-2616):
ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt
There are also other RFC's that specify how data is transferred and so
on. You might want to read RFC's about MIME's too. Here is good place to
search for those:
http://www.rfc-editor.org/rfcsearch.html
Also there are some differences how browsers process those header
fields. You need to little experiment how they work.
Thanks,
Vesa Jääskeläinen
More information about the En-Nut-Discussion
mailing list