@@ -18,25 +18,44 @@ ArduinoHttpServer::AbstractStreamHttpReply::AbstractStreamHttpReply(Stream& stre
18
18
19
19
}
20
20
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
+
21
42
// ------------------------------------------------------------------------------
22
43
// ! \brief Send this reply / print this reply to stream.
23
44
// ! \todo: Accept char* also for data coming directly from flash.
24
45
void ArduinoHttpServer::AbstractStreamHttpReply::send (const String& data, const String& title)
25
46
{
26
- // Read away remaining bytes.
27
- while (getStream ().read ()>=0 );
28
-
29
47
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);
38
49
getStream ().print ( data ); getStream ().print ( AHS_F (" \r\n " ) );
50
+ DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
51
+ }
39
52
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);
40
59
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN (" done." );
41
60
}
42
61
0 commit comments