MCPcopy Create free account
hub / github.com/SmingHub/Sming / getNextStream

Method getNextStream

Sming/Components/Network/src/Data/Stream/MultipartStream.cpp:17–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <esp_system.h>
16
17IDataSourceStream* 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
66const char* MultipartStream::getBoundary()
67{

Callers

nothing calls this directly

Calls 5

ensureCapacityMethod · 0.45
printMethod · 0.45
containsMethod · 0.45
availableMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected