@@ -18,42 +18,37 @@ ArduinoHttpServer::AbstractStreamHttpReply::AbstractStreamHttpReply(Stream& stre
18
18
19
19
}
20
20
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)
25
22
{
26
23
// Read away remaining bytes.
27
24
while (getStream ().read ()>=0 );
28
25
29
- DEBUG_ARDUINO_HTTP_SERVER_PRINT (" Printing Reply ... " );
30
-
31
26
getStream ().print ( AHS_F (" HTTP/1.1 " ) );
32
27
getStream ().print ( getCode () + " " );
33
- getStream ().print ( title + " \r\n " );
34
28
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
+ }
36
33
getStream ().print ( AHS_F (" Content-Type: " ) ); getStream ().print ( m_contentType ); getStream ().print ( AHS_F (" \r\n " ) );
37
34
getStream ().print ( AHS_F (" \r\n " ) );
38
- getStream (). print ( data ); getStream (). print ( AHS_F ( " \r\n " ) );
35
+ }
39
36
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 " ) );
40
45
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
41
46
}
42
47
43
48
void ArduinoHttpServer::AbstractStreamHttpReply::send (const uint8_t * buf, const size_t size) {
44
- // Read away remaining bytes.
45
- while (getStream ().read ()>=0 );
46
-
47
49
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);
55
51
getStream ().write (buf, size);
56
-
57
52
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
58
53
}
59
54
0 commit comments