Reputation: 3571
I recently came across embedded mongoose web server library that I plan to use for a project. However, only after spending a lot of time on Google and Stack Overflow was I able to get the basic "hello world" example working in C language.
Now that I am not able to find any online tutorials or existing questions on Stack Overflow about my doubts, I would like to question them here. I have following questions about usage of Mongoose server-:
Generally, in more popular servers like Apache when the user calls for "localhost/help.text" he gets "help.txt" displayed in the browser. However, in the embedded version of Mongoose how do I know what the user has requested to that I can pass on that particular file (or raw data in my case) depending upon what was requested by the user?
From examples, I was able to learn how raw data is sent to the client's browser, however what if I want to send a file. Say for example I send an HTML file are all the assosiated files sent too? Generally, when CSS and javascript files are encountered by the browser it sends another request to the server for those files and then server sends back those file. However, recently I came across this question and it confuses me a little (although I haven't tried what is says): Display html and pass the data from html to mongoose server
I visited the file upload example of Mongoose given on the website, but I couldn't much unserstand what was going on.
These are some very basic features that a server has and perhaps because of scarcity of good tutorials I am not able to find out the solution to my problem while it may be pretty trivial.
On a slightly different note, I would like to learn more about features of Mongoose embedded server and how they can be used.
Pardon me if this question seems very basic, but from the reviews I have read and from what the Mongoose's website says, I think mongoose is a great embedded web server if only a little more documentation of the same could be found.
Thank you.
Upvotes: 1
Views: 2184
Reputation: 857
The answer is in the example, https://github.com/cesanta/mongoose/blob/master/examples/hello.c All the information is in the struct mg_connection
structure passed to the callback.
You should not do that directly. Just reply with the HTML page, and browser will request all required files itself by sending separate request per file.
Yes you can upload files. There is an example https://github.com/cesanta/mongoose/blob/master/examples/upload.c on how to do that.
Upvotes: 1