| 15 | #include <esp_system.h> |
| 16 | |
| 17 | IDataSourceStream* MultipartStream::getNextStream() |
| 18 | { |
| 19 | if(footerSent) { |
| 20 | return nullptr; |
| 21 | } |
| 22 | |
| 23 | // Return content, if available |
| 24 | if(bodyPart.stream != nullptr) { |
| 25 | auto stream = bodyPart.stream; |
| 26 | bodyPart.stream = nullptr; |
| 27 | return stream; |
| 28 | } |
| 29 | |
| 30 | // Fetch next part to send |
| 31 | bodyPart = producer(); |
| 32 | |
| 33 | // Generate header fragment |
| 34 | auto stream = new MemoryDataStream(); |
| 35 | stream->ensureCapacity(4 + 16 + 4); |
| 36 | stream->print("\r\n"); |
| 37 | stream->print("--"); |
| 38 | stream->print(getBoundary()); |
| 39 | if(!bodyPart) { |
| 40 | stream->print("--"); |
| 41 | footerSent = true; |
| 42 | } |
| 43 | stream->print("\r\n"); |
| 44 | |
| 45 | if(bodyPart) { |
| 46 | if(bodyPart.stream != nullptr && !bodyPart.headers->contains(HTTP_HEADER_CONTENT_LENGTH)) { |
| 47 | auto avail = bodyPart.stream->available(); |
| 48 | if(avail >= 0) { |
| 49 | (*bodyPart.headers)[HTTP_HEADER_CONTENT_LENGTH] = avail; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | for(unsigned i = 0; i < bodyPart.headers->count(); i++) { |
| 54 | stream->print((*bodyPart.headers)[i]); |
| 55 | } |
| 56 | |
| 57 | delete bodyPart.headers; |
| 58 | bodyPart.headers = nullptr; |
| 59 | |
| 60 | stream->print("\r\n"); |
| 61 | } |
| 62 | |
| 63 | return stream; |
| 64 | } |
| 65 | |
| 66 | const char* MultipartStream::getBoundary() |
| 67 | { |
nothing calls this directly
no test coverage detected