-
Notifications
You must be signed in to change notification settings - Fork 6
/
HttpMessage.cpp
76 lines (69 loc) · 1.5 KB
/
HttpMessage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "HttpMessage.h"
//#define DEBUG_HTTPMESSAGE
HttpMessage::HttpMessage() :
m_headers()
{
}
HttpMessage::~HttpMessage()
{
LinkedListItem<HttpHeader*>* item = NULL;
while (item = m_headers.getFirst())
{
HttpHeader* header = m_headers.remove(item->getItem());
delete header;
}
}
bool HttpMessage::hasHeader(String name)
{
for (LinkedListItem<HttpHeader*>* i = m_headers.getFirst(); i; i = i->getNext())
{
#if defined(CONSOLE) && defined(DEBUG_HTTPMESSAGE)
CONSOLE.print("Searching Header: ");
CONSOLE.println(i->getItem()->Name);
#endif
if (i->getItem()->Name.equalsIgnoreCase(name))
{
return true;
}
}
return false;
}
HttpHeader* HttpMessage::getHeader(String name)
{
for (LinkedListItem<HttpHeader*>* i = m_headers.getFirst(); i; i = i->getNext())
{
if (i->getItem()->Name == name)
{
return i->getItem();
}
}
return NULL;
}
void HttpMessage::setHeader(String name, String value)
{
HttpHeader * header;
if (hasHeader(name))
{
header = getHeader(name);
#if defined(CONSOLE) && defined(DEBUG_HTTPMESSAGE)
CONSOLE.print("Found existing header: ");
CONSOLE.println(header->Name);
#endif
}
else
{
header = new HttpHeader();
header->Name = name;
header->Value = value;
m_headers.add(header);
}
}
void HttpMessage::printHeaders(Stream *stream)
{
for (LinkedListItem<HttpHeader*>* i = m_headers.getFirst(); i; i = i->getNext())
{
HttpHeader* header = i->getItem();
stream->printf("%s: %s\r\n", header->Name.c_str(), header->Value.c_str());
}
stream->print("\r\n");
}