summaryrefslogtreecommitdiffstats
path: root/plugins/webinterface/httpresponseheader.cpp
blob: 3056f79f93a0eed70b031cfc0fb49f69d10e57e6 (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
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   joris.guisson@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 ***************************************************************************/
#include "httpresponseheader.h"

namespace kt
{
	static TQString ResponseCodeToString(int r)
	{
		switch (r)
		{
			case 200: return "OK";
			case 301: return "Moved Permanently";
			case 304: return "Not Modified";
			case 404: return "Not Found";
		}
		return TQString();
	}
	
	HttpResponseHeader::HttpResponseHeader(int response_code) 
		: response_code(response_code)
	{
	}
	
	HttpResponseHeader::HttpResponseHeader(const HttpResponseHeader & hdr)
	{
		response_code = hdr.response_code;
		fields = hdr.fields;
	}
	
	HttpResponseHeader::~HttpResponseHeader()
	{
	}
	
	void HttpResponseHeader::setResponseCode(int rc)
	{
		response_code = rc;
	}
	
	void HttpResponseHeader::setValue(const TQString & key,const TQString & value)
	{
		fields[key] = value;
	}
		
	TQString HttpResponseHeader::toString() const
	{
		TQString str;
		str += TQString("HTTP/1.1 %1 %2\r\n").arg(response_code).arg(ResponseCodeToString(response_code));
		
		TQMap<TQString,TQString>::const_iterator itr = fields.begin();
		while (itr != fields.end())
		{
			str += TQString("%1: %2\r\n").arg(itr.key()).arg(itr.data());
			itr++;
		}
		str += "\r\n";
		return str;
	}
	


}