HttpHeaders.h revision cb1a99c5
1/*
2 * Copyright 2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _B_HTTP_HEADERS_H_
6#define _B_HTTP_HEADERS_H_
7
8
9#include <List.h>
10#include <String.h>
11
12
13class BHttpHeader {
14public:
15								BHttpHeader();
16								BHttpHeader(const char* string);
17								BHttpHeader(const char* name,
18									const char* value);
19								BHttpHeader(const BHttpHeader& copy);
20
21	// Header data modification
22			void				SetName(const char* name);
23			void				SetValue(const char* value);
24			bool				SetHeader(const char* string);
25
26	// Header data access
27			const char*			Name() const;
28			const char* 		Value() const;
29			const char* 		Header() const;
30
31	// Header data test
32			bool				NameIs(const char* name) const;
33
34	// Overloaded members
35			BHttpHeader&		operator=(const BHttpHeader& other);
36
37private:
38			BString				fName;
39			BString				fValue;
40
41	mutable	BString				fRawHeader;
42	mutable	bool				fRawHeaderValid;
43};
44
45
46class BHttpHeaders {
47public:
48								BHttpHeaders();
49								BHttpHeaders(const BHttpHeaders& copy);
50								~BHttpHeaders();
51
52	// Header list access
53			const char*			HeaderValue(const char* name) const;
54			BHttpHeader&		HeaderAt(int32 index) const;
55
56	// Header count
57			int32				CountHeaders() const;
58
59	// Header list tests
60			int32				HasHeader(const char* name) const;
61
62	// Header add or replacement
63			bool				AddHeader(const char* line);
64			bool				AddHeader(const char* name,
65									const char* value);
66			bool				AddHeader(const char* name,
67									int32 value);
68
69	// Header deletion
70			void 				Clear();
71
72	// Overloaded operators
73			BHttpHeaders&		operator=(const BHttpHeaders& other);
74			BHttpHeader&		operator[](int32 index) const;
75			const char*			operator[](const char* name) const;
76
77private:
78			void				_EraseData();
79			bool				_AddOrDeleteHeader(BHttpHeader* header);
80
81private:
82			BList				fHeaderList;
83};
84
85#endif // _B_HTTP_HEADERS_H_
86