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