Skip to content

ESP8266WebServer: adding additional headers #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
holgerlembke opened this issue May 11, 2015 · 8 comments
Closed

ESP8266WebServer: adding additional headers #224

holgerlembke opened this issue May 11, 2015 · 8 comments

Comments

@holgerlembke
Copy link
Contributor

With current implementation, how do I add additional header lines when answering a request?

I found no solution, so I made some changes. I dislike my solution, I would prefer something with overloading. But that might break all the existing solution/samples/etc.

@holgerlembke
Copy link
Contributor Author

in ESP8266WebServer.h

// send response to the client
// code - HTTP response code, can be 200 or 404
// content_type - HTTP content type, like "text/plain" or "image/png"
// content - actual content body
void send(int code, const char* content_type = NULL, String content = String(""));
void sendh(int code, const char* content_type = NULL, String content = String(""), String headerlines = String(""));

and in ESP8266WebServer.cpp

void ESP8266WebServer::sendh(int code, const char* content_type, String content, String headerlines) {
String response = "HTTP/1.1 ";
response += String(code);
response += " ";
response += _responseCodeToString(code);
response += "\r\n";

if (!content_type)
content_type = "text/html";
_appendHeader(response, "Content-Type", content_type);

// weitere kopfzeilen
response += headerlines;

response += "\r\n";
response += content;
_currentClient.print(response);
}

void ESP8266WebServer::send(int code, const char* content_type, String content) {
sendh(code,content_type,content,"");
}

@igrr
Copy link
Member

igrr commented May 14, 2015

8c1a40b adds a server.sendHeader(key, value) function which may be used before calling server.send.

@holgerlembke
Copy link
Contributor Author

Nice. Looks fine to me.

Next thing I'm not entirely sure if it is a good solution:

I like the on(url,function)-idea.

On the other hand: i have a precompiled binary blob of filenames+html with an index. So I don't use the on-method (because that would result in a double index, one in the on-list, one in my blob) but I go through the list in the "onNotFound"-event.

It works and I'm fine with it.

But it doesn't really "looks as designed" to me.

Just to vent my feelings. :-)

@igrr
Copy link
Member

igrr commented May 14, 2015

Right now SD card webserver and Spiffs webserver samples also use
onNotFound handler. Actually I want to add a stack of handlers much in the
same way as it's done in node.js — that would allow for middleware
libraries that plug easily into the webserver.

So thanks for letting me know that you also need this :)
On May 14, 2015 16:56, "holgerlembke" [email protected] wrote:

Nice. Looks fine to me.

Next thing I'm not entirely sure if it is a good solution:

I like the on(url,function)-idea.

On the other hand: i have a precompiled binary blob of filenames+html with
an index. So I don't use the on-method (because that would result in a
double index, one in the on-list, one in my blob) but I go through the list
in the "onNotFound"-event.

It works and I'm fine with it.

But it doesn't really "looks as designed" to me.

Just to vent my feelings. :-)


Reply to this email directly or view it on GitHub
#224 (comment).

@holgerlembke
Copy link
Contributor Author

My current concern is that all the html pages/strings go into heap space. and as far as I can see, that is a major limit currently. I run at about 25k free...

On the other hand, flash rom seems to be more than enough, new models coming with even more... that's why I go for the blob solution. So if I find some time, I will dig into some ideas about saving html pages into flash via web-server-upload.

@igrr
Copy link
Member

igrr commented May 14, 2015

We have SPI flash filesystem working already, and a tool which will pack
your files and upload them along with the sketch. Should be completed
shortly.
On May 14, 2015 17:39, "holgerlembke" [email protected] wrote:

My current concern is that all the html pages/strings go into heap space.
and as far as I can see, that is a major limit currently. I run at about
25k free...

On the other hand, flash rom seems to be more than enough, new models
coming with even more... that's why I go for the blob solution. So if I
find some time, I will dig into some ideas about saving html pages into
flash via web-server-upload.


Reply to this email directly or view it on GitHub
#224 (comment).

@holgerlembke
Copy link
Contributor Author

I have seen the work. Hopefully it does not end in something tooo difficult. Fiddling around with make files and such. I like my "upload with web server"-idea... :-)

Meanwhile I file issues.... #240

@igrr igrr closed this as completed May 23, 2015
chadouming pushed a commit to chadouming/Arduino that referenced this issue Jun 17, 2015
…index.html stored in folder SKETCH_FOLDER/docs/. Fixes esp8266#224
@martin072
Copy link

Hi,

I noticed this issue, and was wondering if it will be implemented? I need to pass some extra headers with the webServer.send command, but I noticed adding custom headers is not yet implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants