Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HttpHeaderBuilder.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * HttpHeaderBuilder.h
8  *
9  ****/
10 
11 #ifndef _SMING_CORE_NETWORK_HTTP_HTTP_HEADER_BUILDER_H_
12 #define _SMING_CORE_NETWORK_HTTP_HTTP_HEADER_BUILDER_H_
13 
14 #include "HttpHeaders.h"
15 
18 {
19 public:
20  int onHeaderField(const char* at, size_t length)
21  {
22  if(lastWasValue) {
23  // we are starting to process new header - setLength keeps allocated memory
24  lastData.setLength(0);
25  lastWasValue = false;
26  }
27  lastData.concat(at, length);
28 
29  return 0;
30  }
31 
32  int onHeaderValue(HttpHeaders& headers, const char* at, size_t length)
33  {
34  if(!lastWasValue) {
35  currentField = lastData;
36  headers[currentField] = nullptr;
37  lastWasValue = true;
38  }
39  headers[currentField].concat(at, length);
40  return 0;
41  }
42 
43  void reset()
44  {
45  lastWasValue = true;
46  lastData = nullptr;
47  currentField = nullptr;
48  }
49 
50 private:
51  bool lastWasValue = true;
52  String lastData;
53  String currentField;
54 };
55 
56 #endif /* _SMING_CORE_NETWORK_HTTP_HTTP_HEADER_BUILDER_H_ */
bool setLength(unsigned int length)
set the string length accordingly, expanding if necessary
The string class.
Definition: WString.h:104
Encapsulates a set of HTTP header information.
Definition: HttpHeaders.h:96
Re-assembles headers from fragments via onHeaderField / onHeaderValue callbacks.
Definition: HttpHeaderBuilder.h:17