@@ -18,42 +18,37 @@ ArduinoHttpServer::AbstractStreamHttpReply::AbstractStreamHttpReply(Stream& stre
1818
1919}
2020
21- // ------------------------------------------------------------------------------
22- // ! \brief Send this reply / print this reply to stream.
23- // ! \todo: Accept char* also for data coming directly from flash.
24- void ArduinoHttpServer::AbstractStreamHttpReply::send (const String& data, const String& title)
21+ void ArduinoHttpServer::AbstractStreamHttpReply::sendHeader (size_t size)
2522{
2623 // Read away remaining bytes.
2724 while (getStream ().read ()>=0 );
2825
29- DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
30-
3126 getStream ().print ( AHS_F (" HTTP/1.1 " ) );
3227 getStream ().print ( getCode () + " " );
33- getStream ().print ( title + " \r\n " );
3428 getStream ().print ( AHS_F (" Connection: close\r\n " ) );
35- getStream ().print ( AHS_F (" Content-Length: " ) ); getStream ().print ( data.length ()); getStream ().print ( AHS_F (" \r\n " ) );
29+ if (size > 0 )
30+ {
31+ getStream ().print ( AHS_F (" Content-Length: " ) ); getStream ().print (size); getStream ().print ( AHS_F (" \r\n " ) );
32+ }
3633 getStream ().print ( AHS_F (" Content-Type: " ) ); getStream ().print ( m_contentType ); getStream ().print ( AHS_F (" \r\n " ) );
3734 getStream ().print ( AHS_F (" \r\n " ) );
38- getStream (). print ( data ); getStream (). print ( AHS_F ( " \r\n " ) );
35+ }
3936
37+ // ------------------------------------------------------------------------------
38+ // ! \brief Send this reply / print this reply to stream.
39+ // ! \todo: Accept char* also for data coming directly from flash.
40+ void ArduinoHttpServer::AbstractStreamHttpReply::send (const String& data, const String& title)
41+ {
42+ DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
43+ AbstractStreamHttpReply::sendHeader (data.length ());
44+ getStream ().print ( data ); getStream ().print ( AHS_F (" \r\n " ) );
4045 DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
4146}
4247
4348void ArduinoHttpServer::AbstractStreamHttpReply::send (const uint8_t * buf, const size_t size) {
44- // Read away remaining bytes.
45- while (getStream ().read ()>=0 );
46-
4749 DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
48-
49- getStream ().print ( AHS_F (" HTTP/1.1 " ) );
50- getStream ().print ( getCode () + " " );
51- getStream ().print ( AHS_F (" Connection: close\r\n " ) );
52- getStream ().print ( AHS_F (" Content-Length: " ) ); getStream ().print (size); getStream ().print ( AHS_F (" \r\n " ) );
53- getStream ().print ( AHS_F (" Content-Type: " ) ); getStream ().print ( m_contentType ); getStream ().print ( AHS_F (" \r\n " ) );
54- getStream ().print ( AHS_F (" \r\n " ) );
50+ AbstractStreamHttpReply::sendHeader (size);
5551 getStream ().write (buf, size);
56-
5752 DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
5853}
5954
0 commit comments