Skip to content

Commit 1c5cef0

Browse files
Add support for sending binary files
1 parent 398039e commit 1c5cef0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/internals/StreamHttpReply.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ void ArduinoHttpServer::AbstractStreamHttpReply::send(const String& data, const
4040
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN("done.");
4141
}
4242

43+
void ArduinoHttpServer::AbstractStreamHttpReply::send(const uint8_t* buf, const size_t size) {
44+
// Read away remaining bytes.
45+
while(getStream().read()>=0);
46+
47+
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") );
55+
getStream().write(buf, size);
56+
57+
DEBUG_ARDUINO_HTTP_SERVER_PRINTLN("done.");
58+
}
59+
4360

4461
Stream& ArduinoHttpServer::AbstractStreamHttpReply::getStream()
4562
{

src/internals/StreamHttpReply.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AbstractStreamHttpReply
2626

2727
public:
2828
virtual void send(const String& data, const String& title);
29+
virtual void send(const uint8_t* buf, const size_t size);
2930

3031
protected:
3132
AbstractStreamHttpReply(Stream& stream, const String& contentType, const String& code);
@@ -81,6 +82,7 @@ class StreamHttpReply: public AbstractStreamHttpReply
8182
public:
8283
StreamHttpReply(Stream& stream, const String& contentType);
8384
virtual void send(const String& data, const bool gzipencoded=false) { AbstractStreamHttpReply::send(data, "OK"); };
85+
virtual void send(const uint8_t *buf, const size_t size) { AbstractStreamHttpReply::send(buf, size); };
8486
};
8587

8688

0 commit comments

Comments
 (0)