@@ -18,25 +18,44 @@ ArduinoHttpServer::AbstractStreamHttpReply::AbstractStreamHttpReply(Stream& stre
1818
1919}
2020
21+ void ArduinoHttpServer::AbstractStreamHttpReply::sendHeader (
22+ size_t size, const String& title) {
23+ // Read away remaining bytes.
24+ while (getStream ().read () >= 0 ) {
25+ }
26+
27+ getStream ().print (AHS_F (" HTTP/1.1 " ));
28+ getStream ().print (getCode () + " " );
29+ getStream ().print (title + " \r\n " );
30+ getStream ().print (AHS_F (" Connection: close\r\n " ));
31+ if (size > 0 ) {
32+ getStream ().print (AHS_F (" Content-Length: " ));
33+ getStream ().print (size);
34+ getStream ().print (AHS_F (" \r\n " ));
35+ }
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 " ));
40+ }
41+
2142// ------------------------------------------------------------------------------
2243// ! \brief Send this reply / print this reply to stream.
2344// ! \todo: Accept char* also for data coming directly from flash.
2445void ArduinoHttpServer::AbstractStreamHttpReply::send (const String& data, const String& title)
2546{
26- // Read away remaining bytes.
27- while (getStream ().read ()>=0 );
28-
2947 DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
30-
31- getStream ().print ( AHS_F (" HTTP/1.1 " ) );
32- getStream ().print ( getCode () + " " );
33- getStream ().print ( title + " \r\n " );
34- 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 " ) );
36- getStream ().print ( AHS_F (" Content-Type: " ) ); getStream ().print ( m_contentType ); getStream ().print ( AHS_F (" \r\n " ) );
37- getStream ().print ( AHS_F (" \r\n " ) );
48+ AbstractStreamHttpReply::sendHeader (data.length (), title);
3849 getStream ().print ( data ); getStream ().print ( AHS_F (" \r\n " ) );
50+ DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
51+ }
3952
53+ void ArduinoHttpServer::AbstractStreamHttpReply::send (const uint8_t * buf,
54+ const size_t size,
55+ const String& title) {
56+ DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
57+ AbstractStreamHttpReply::sendHeader (size, title);
58+ getStream ().write (buf, size);
4059 DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
4160}
4261
0 commit comments