28 "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
35static const char*
methods[] = {
"?",
"GET",
"HEAD",
"POST",
36 "PUT",
"DELETE",
"TRACE",
"OPTIONS",
37 "CONNECT",
"PATCH",
nullptr};
79 for (
auto& ptr :
lines){
87 if (value !=
nullptr && strlen(value) > 0) {
88 LOGD(
"HttpHeader::put %s %s", key, value);
92 LOGE(
"HttpHeader::put - did not add HttpHeaderLine for %s", key);
98 LOGD(
"HttpHeader::put -> '%s' : '%s'", key, value);
105 LOGI(
"- is_chunked!!!");
113 LOGD(
"HttpHeader::put - value ignored because it is null for %s", key);
120 LOGD(
"HttpHeader::put %s %d", key, value);
124 LOGW(
"value is > 1000");
136 LOGD(
"HttpHeader::put -> %s", (
const char*)line);
140 LOGD(
"HttpHeader::put - no key found in %s", line);
143 char* key = (
char*)line;
147 const char* value = line + pos + 1;
148 if (value[0] ==
' ') {
149 value = line + pos + 2;
151 return put((
const char*)key, value);
155 const char*
get(
const char* key) {
156 for (
auto& line_ptr :
lines) {
159 line_ptr->key = trimmed.c_str();
162 const char* result = line_ptr->value.c_str();
163 return line_ptr->active ? result :
nullptr;
172 LOGD(
"HttpHeader::readLine -> %s", str);
178 LOGD(
"HttpHeader::writeHeaderLine: %s", header.
key.
c_str());
180 LOGD(
"HttpHeader::writeHeaderLine - not active");
184 LOGD(
"HttpHeader::writeHeaderLine - ignored because value is null");
194 out.print(msg_str.
c_str());
198 int len = strlen(msg);
200 LOGI(
" -> %s ", msg);
221 LOGD(
"HttpHeader::read");
234 LOGI(
"Waiting for data...");
247 LOGE(
"Failed to read the first line of the header");
254 if (len == 0 && in.
available() == 0)
break;
274 LOGI(
"HttpHeader::write");
278 for (
auto& line_ptr :
lines) {
289 for (
auto& line :
lines) {
290 line->active =
false;
353 LOGI(
" -> %s ",
"<CR LF>");
358 if (key !=
nullptr) {
359 for (
auto& line_ptr :
lines) {
360 if (line_ptr->key.c_str() !=
nullptr) {
361 if (line_ptr->key.equalsIgnoreCase(key)) {
370 lines.push_back(new_line);
374 LOGI(
"HttpHeader::headerLine %s",
"The key must not be null");
381 for (
int j = 0;
methods[j] !=
nullptr; j++) {
382 const char* action =
methods[j];
383 int len = strlen(action);
384 if (strncmp(action, line, len) == 0) {
417 LOGD(
"HttpRequestHeader::write1stLine");
422 msg_str = method_str;
428 size_t written = out.print(msg);
430 int len = strlen(msg);
433 if (written != len) {
434 LOGE(
"Failed to write the first line of the header: %d of %d", (
int)written, len);
443 LOGI(
"HttpRequestHeader::parse1stLine %s", line);
445 int space1 = line_str.
indexOf(
" ");
446 int space2 = line_str.
indexOf(
" ", space1 + 1);
469 LOGI(
"HttpReplyHeader::setValues");
479 LOGI(
"HttpReplyHeader::readExt");
482 while (strlen(line) != 0) {
490 LOGI(
"HttpReplyHeader::write1stLine");
499 int written = out.print(msg);
500 int len = strlen(msg);
502 if (written != len) {
503 LOGE(
"Failed to write the first line of the header: %d of %d", written, len);
513 LOGD(
"HttpReplyHeader::parse1stLine: %s", line);
515 int space1 = line_str.
indexOf(
' ', 0);
516 int space2 = line_str.
indexOf(
' ', space1 + 1);
524 status.
substring(line_str, space1 + 1, space2);
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
MethodID
supported http methods
Definition HttpTypes.h:3
bool connected()
Definition Arduino.h:167
virtual void flush()
Definition Arduino.h:130
virtual int available()
Definition Arduino.h:139
#define URL_CLIENT_TIMEOUT
Definition esp8266.h:23