MultipartStream.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * MultipartStream.h
8  *
9  * @author Slavey Karadzhov <slaff@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
17 
24 {
25 public:
29  struct BodyPart {
30  HttpHeaders* headers{nullptr};
31  IDataSourceStream* stream{nullptr};
32 
33  // Must always have headers, stream is optional (can be empty)
34  explicit operator bool() const
35  {
36  return headers != nullptr;
37  }
38  };
39 
43  using Producer = Delegate<BodyPart()>;
44 
45  MultipartStream(Producer delegate) : producer(delegate)
46  {
47  }
48 
50  {
51  delete bodyPart.headers;
52  delete bodyPart.stream;
53  }
54 
60  const char* getBoundary();
61 
62 protected:
63  IDataSourceStream* getNextStream() override;
64 
65 private:
66  Producer producer;
67  BodyPart bodyPart;
68  char boundary[16]{};
69  bool footerSent{false};
70 };
MultipartStream(Producer delegate)
Definition: MultipartStream.h:55
Base class for read-only stream.
Definition: DataSourceStream.h:45
IDataSourceStream * stream
Definition: MultipartStream.h:51
Encapsulates a set of HTTP header information.
Definition: HttpHeaders.h:34
Each result item contains a set of headers plus content stream.
Definition: MultipartStream.h:39
Read-only stream for creating HTTP multi-part content.
Definition: MultipartStream.h:23
const char * getBoundary()
Returns the generated boundary.
~MultipartStream()
Definition: MultipartStream.h:59
IDataSourceStream * getNextStream() override
Inherited class must implement this.
Base class for read-only stream which generates output from multiple source streams.
Definition: MultiStream.h:23
HttpHeaders * headers
Definition: MultipartStream.h:50