Skip to content

Commit 0128fcd

Browse files
Correctly handle title
1 parent b7a59c8 commit 0128fcd

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/internals/StreamHttpReply.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ ArduinoHttpServer::AbstractStreamHttpReply::AbstractStreamHttpReply(Stream& stre
1818

1919
}
2020

21-
void ArduinoHttpServer::AbstractStreamHttpReply::sendHeader(size_t size)
22-
{
21+
void ArduinoHttpServer::AbstractStreamHttpReply::sendHeader(
22+
size_t size, const String& title) {
2323
// Read away remaining bytes.
24-
while(getStream().read()>=0);
24+
while (getStream().read() >= 0) {
25+
}
2526

26-
getStream().print( AHS_F("HTTP/1.1 ") );
27-
getStream().print( getCode() + " ");
28-
getStream().print( AHS_F("Connection: close\r\n") );
29-
if (size > 0)
30-
{
31-
getStream().print( AHS_F("Content-Length: ") ); getStream().print(size); getStream().print( AHS_F("\r\n") );
27+
getStream().print(AHS_F("HTTP/1.1 "));
28+
getStream().print(getCode() + " ");
29+
getStream().print(title + "\r\n");
30+
getStream().print(AHS_F("Connection: keep-alive\r\n"));
31+
if (size > 0) {
32+
getStream().print(AHS_F("Content-Length: "));
33+
getStream().print(size);
34+
getStream().print(AHS_F("\r\n"));
3235
}
33-
getStream().print( AHS_F("Content-Type: ") ); getStream().print( m_contentType ); getStream().print( AHS_F("\r\n") );
34-
getStream().print( AHS_F("\r\n") );
36+
getStream().print(AHS_F("Content-Type: "));
37+
getStream().print(m_contentType);
38+
getStream().print(AHS_F("\r\n"));
39+
getStream().print(AHS_F("\r\n"));
3540
}
3641

3742
//------------------------------------------------------------------------------
@@ -40,14 +45,16 @@ void ArduinoHttpServer::AbstractStreamHttpReply::sendHeader(size_t size)
4045
void ArduinoHttpServer::AbstractStreamHttpReply::send(const String& data, const String& title)
4146
{
4247
DEBUG_ARDUINO_HTTP_SERVER_PRINT("Printing Reply ... ");
43-
AbstractStreamHttpReply::sendHeader(data.length());
48+
AbstractStreamHttpReply::sendHeader(data.length(), title);
4449
getStream().print( data ); getStream().print( AHS_F("\r\n") );
4550
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN("done.");
4651
}
4752

48-
void ArduinoHttpServer::AbstractStreamHttpReply::send(const uint8_t* buf, const size_t size) {
53+
void ArduinoHttpServer::AbstractStreamHttpReply::send(const uint8_t* buf,
54+
const size_t size,
55+
const String& title) {
4956
DEBUG_ARDUINO_HTTP_SERVER_PRINT("Printing Reply ... ");
50-
AbstractStreamHttpReply::sendHeader(size);
57+
AbstractStreamHttpReply::sendHeader(size, title);
5158
getStream().write(buf, size);
5259
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN("done.");
5360
}

src/internals/StreamHttpReply.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class AbstractStreamHttpReply
2525
{
2626

2727
public:
28-
virtual void sendHeader(size_t size);
28+
virtual void sendHeader(size_t size, const String& title);
2929
virtual void send(const String& data, const String& title);
30-
virtual void send(const uint8_t* buf, const size_t size);
30+
virtual void send(const uint8_t* buf, const size_t size, const String& title);
3131

3232
protected:
3333
AbstractStreamHttpReply(Stream& stream, const String& contentType, const String& code);
@@ -83,7 +83,8 @@ class StreamHttpReply: public AbstractStreamHttpReply
8383
public:
8484
StreamHttpReply(Stream& stream, const String& contentType);
8585
virtual void send(const String& data, const bool gzipencoded=false) { AbstractStreamHttpReply::send(data, "OK"); };
86-
virtual void send(const uint8_t *buf, const size_t size) { AbstractStreamHttpReply::send(buf, size); };
86+
virtual void send(const uint8_t* buf, const size_t size, const String& title="OK") { AbstractStreamHttpReply::send(buf, size, title); };
87+
virtual void sendHeader(size_t size, const String& title="OK") { AbstractStreamHttpReply::sendHeader(size, title); }
8788
};
8889

8990

0 commit comments

Comments
 (0)