summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/httpheaders.cpp
blob: 73c92c8f102ecbf49179ec3a883117658f2a48bf (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
 * @file httpheaders.cpp
 * @brief Implementation of the HTTPHeaders class
 *
 * $LicenseInfo:firstyear=2012&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2012-2013, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "httpheaders.h"

#include "llstring.h"


namespace LLCore
{


HttpHeaders::HttpHeaders()
	: RefCounted(true)
{}


HttpHeaders::~HttpHeaders()
{}


void
HttpHeaders::clear()
{
	mHeaders.clear();
}


void HttpHeaders::append(const std::string & name, const std::string & value)
{
	mHeaders.push_back(value_type(name, value));
}


void HttpHeaders::append(const char * name, const char * value)
{
	mHeaders.push_back(value_type(name, value));
}


void HttpHeaders::appendNormal(const char * header, size_t size)
{
	std::string name;
	std::string value;

	int col_pos(0);
	for (; col_pos < size; ++col_pos)
	{
		if (':' == header[col_pos])
			break;
	}
	
	if (col_pos < size)
	{
		// Looks like a header, split it and normalize.
		// Name is everything before the colon, may be zero-length.
		name.assign(header, col_pos);

		// Value is everything after the colon, may also be zero-length.
		const size_t val_len(size - col_pos - 1);
		if (val_len)
		{
			value.assign(header + col_pos + 1, val_len);
		}

		// Clean the strings
		LLStringUtil::toLower(name);
		LLStringUtil::trim(name);
		LLStringUtil::trimHead(value);
	}
	else
	{
		// Uncertain what this is, we'll pack it as
		// a name without a value.  Won't clean as we don't
		// know what it is...
		name.assign(header, size);
	}

	mHeaders.push_back(value_type(name, value));
}


// Find from end to simulate a tradition of using single-valued
// std::map for this in the past.
const std::string * HttpHeaders::find(const std::string &name) const
{
	const_reverse_iterator iend(rend());
	for (const_reverse_iterator iter(rbegin()); iend != iter; ++iter)
	{
		if ((*iter).first == name)
		{
			return &(*iter).second;
		}
	}
	return NULL;
}


// Standard Iterators
HttpHeaders::iterator HttpHeaders::begin()
{
	return mHeaders.begin();
}


HttpHeaders::const_iterator HttpHeaders::begin() const
{
	return mHeaders.begin();
}


HttpHeaders::iterator HttpHeaders::end()
{
	return mHeaders.end();
}


HttpHeaders::const_iterator HttpHeaders::end() const
{
	return mHeaders.end();
}


// Standard Reverse Iterators
HttpHeaders::reverse_iterator HttpHeaders::rbegin()
{
	return mHeaders.rbegin();
}


HttpHeaders::const_reverse_iterator HttpHeaders::rbegin() const
{
	return mHeaders.rbegin();
}


HttpHeaders::reverse_iterator HttpHeaders::rend()
{
	return mHeaders.rend();
}


HttpHeaders::const_reverse_iterator HttpHeaders::rend() const
{
	return mHeaders.rend();
}


// Return the raw container to the caller.
//
// To be used FOR UNIT TESTS ONLY.
//
HttpHeaders::container_t & HttpHeaders::getContainerTESTONLY()
{
	return mHeaders;
}


}   // end namespace LLCore