HttpHeaderBuilder.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  * HttpHeaderBuilder.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "HttpHeaders.h"
14 
20 {
21 public:
22  int onHeaderField(const char* at, size_t length)
23  {
24  if(lastWasValue) {
25  // we are starting to process new header - setLength keeps allocated memory
26  lastData.setLength(0);
27  lastWasValue = false;
28  }
29  lastData.concat(at, length);
30 
31  return 0;
32  }
33 
34  int onHeaderValue(HttpHeaders& headers, const char* at, size_t length)
35  {
36  if(!lastWasValue) {
37  currentField = lastData;
38  headers[currentField] = nullptr;
39  lastWasValue = true;
40  }
41  headers[currentField].concat(at, length);
42  return 0;
43  }
44 
45  void reset()
46  {
47  lastWasValue = true;
48  lastData = nullptr;
49  currentField = nullptr;
50  }
51 
52 private:
53  bool lastWasValue = true;
54  String lastData;
55  String currentField;
56 };
Re-assembles headers from fragments via onHeaderField / onHeaderValue callbacks.
Definition: HttpHeaderBuilder.h:20
int onHeaderValue(HttpHeaders &headers, const char *at, size_t length)
Definition: HttpHeaderBuilder.h:34
void reset()
Definition: HttpHeaderBuilder.h:45
int onHeaderField(const char *at, size_t length)
Definition: HttpHeaderBuilder.h:22
Encapsulates a set of HTTP header information.
Definition: HttpHeaders.h:35
The String class.
Definition: WString.h:137
bool concat(const String &str)
Definition: WString.h:323
bool setLength(size_t length)
set the string length accordingly, expanding if necessary