1603e0bdfSNiels Sascha Reedijk /* 2603e0bdfSNiels Sascha Reedijk * Copyright 2010 Haiku Inc. All rights reserved. 3603e0bdfSNiels Sascha Reedijk * Distributed under the terms of the MIT License. 4603e0bdfSNiels Sascha Reedijk */ 5603e0bdfSNiels Sascha Reedijk #ifndef _B_HTTP_HEADERS_H_ 6603e0bdfSNiels Sascha Reedijk #define _B_HTTP_HEADERS_H_ 7603e0bdfSNiels Sascha Reedijk 8603e0bdfSNiels Sascha Reedijk 9603e0bdfSNiels Sascha Reedijk #include <List.h> 10603e0bdfSNiels Sascha Reedijk #include <Message.h> 11603e0bdfSNiels Sascha Reedijk #include <String.h> 12603e0bdfSNiels Sascha Reedijk 13603e0bdfSNiels Sascha Reedijk 14ce64ffdbSNiels Sascha Reedijk namespace BPrivate { 15ce64ffdbSNiels Sascha Reedijk 16ce64ffdbSNiels Sascha Reedijk namespace Network { 17*70b63f18SNiels Sascha Reedijk 18ce64ffdbSNiels Sascha Reedijk 19603e0bdfSNiels Sascha Reedijk class BHttpHeader { 20603e0bdfSNiels Sascha Reedijk public: 21603e0bdfSNiels Sascha Reedijk BHttpHeader(); 22603e0bdfSNiels Sascha Reedijk BHttpHeader(const char* string); 23603e0bdfSNiels Sascha Reedijk BHttpHeader(const char* name, 24603e0bdfSNiels Sascha Reedijk const char* value); 25603e0bdfSNiels Sascha Reedijk BHttpHeader(const BHttpHeader& copy); 26603e0bdfSNiels Sascha Reedijk 27603e0bdfSNiels Sascha Reedijk // Header data modification 28603e0bdfSNiels Sascha Reedijk void SetName(const char* name); 29603e0bdfSNiels Sascha Reedijk void SetValue(const char* value); 30603e0bdfSNiels Sascha Reedijk bool SetHeader(const char* string); 31603e0bdfSNiels Sascha Reedijk 32603e0bdfSNiels Sascha Reedijk // Header data access 33603e0bdfSNiels Sascha Reedijk const char* Name() const; 34603e0bdfSNiels Sascha Reedijk const char* Value() const; 35603e0bdfSNiels Sascha Reedijk const char* Header() const; 36603e0bdfSNiels Sascha Reedijk 37603e0bdfSNiels Sascha Reedijk // Header data test 38603e0bdfSNiels Sascha Reedijk bool NameIs(const char* name) const; 39603e0bdfSNiels Sascha Reedijk 40603e0bdfSNiels Sascha Reedijk // Overloaded members 41603e0bdfSNiels Sascha Reedijk BHttpHeader& operator=(const BHttpHeader& other); 42603e0bdfSNiels Sascha Reedijk 43603e0bdfSNiels Sascha Reedijk private: 44603e0bdfSNiels Sascha Reedijk BString fName; 45603e0bdfSNiels Sascha Reedijk BString fValue; 46603e0bdfSNiels Sascha Reedijk 47603e0bdfSNiels Sascha Reedijk mutable BString fRawHeader; 48603e0bdfSNiels Sascha Reedijk mutable bool fRawHeaderValid; 49603e0bdfSNiels Sascha Reedijk }; 50603e0bdfSNiels Sascha Reedijk 51603e0bdfSNiels Sascha Reedijk 52603e0bdfSNiels Sascha Reedijk class BHttpHeaders { 53603e0bdfSNiels Sascha Reedijk public: 54603e0bdfSNiels Sascha Reedijk BHttpHeaders(); 55603e0bdfSNiels Sascha Reedijk BHttpHeaders(const BHttpHeaders& copy); 56603e0bdfSNiels Sascha Reedijk ~BHttpHeaders(); 57603e0bdfSNiels Sascha Reedijk 58603e0bdfSNiels Sascha Reedijk // Header list access 59603e0bdfSNiels Sascha Reedijk const char* HeaderValue(const char* name) const; 60603e0bdfSNiels Sascha Reedijk BHttpHeader& HeaderAt(int32 index) const; 61603e0bdfSNiels Sascha Reedijk 62603e0bdfSNiels Sascha Reedijk // Header count 63603e0bdfSNiels Sascha Reedijk int32 CountHeaders() const; 64603e0bdfSNiels Sascha Reedijk 65603e0bdfSNiels Sascha Reedijk // Header list tests 66603e0bdfSNiels Sascha Reedijk int32 HasHeader(const char* name) const; 67603e0bdfSNiels Sascha Reedijk 68603e0bdfSNiels Sascha Reedijk // Header add or replacement 69603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* line); 70603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* name, 71603e0bdfSNiels Sascha Reedijk const char* value); 72603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* name, 73603e0bdfSNiels Sascha Reedijk int32 value); 74603e0bdfSNiels Sascha Reedijk 75603e0bdfSNiels Sascha Reedijk // Archiving 76603e0bdfSNiels Sascha Reedijk void PopulateFromArchive(BMessage*); 77603e0bdfSNiels Sascha Reedijk void Archive(BMessage*) const; 78603e0bdfSNiels Sascha Reedijk 79603e0bdfSNiels Sascha Reedijk // Header deletion 80603e0bdfSNiels Sascha Reedijk void Clear(); 81603e0bdfSNiels Sascha Reedijk 82603e0bdfSNiels Sascha Reedijk // Overloaded operators 83603e0bdfSNiels Sascha Reedijk BHttpHeaders& operator=(const BHttpHeaders& other); 84603e0bdfSNiels Sascha Reedijk BHttpHeader& operator[](int32 index) const; 85603e0bdfSNiels Sascha Reedijk const char* operator[](const char* name) const; 86603e0bdfSNiels Sascha Reedijk 87603e0bdfSNiels Sascha Reedijk private: 88603e0bdfSNiels Sascha Reedijk void _EraseData(); 89603e0bdfSNiels Sascha Reedijk bool _AddOrDeleteHeader(BHttpHeader* header); 90603e0bdfSNiels Sascha Reedijk 91603e0bdfSNiels Sascha Reedijk private: 92603e0bdfSNiels Sascha Reedijk BList fHeaderList; 93603e0bdfSNiels Sascha Reedijk }; 94603e0bdfSNiels Sascha Reedijk 95*70b63f18SNiels Sascha Reedijk 96ce64ffdbSNiels Sascha Reedijk } // namespace Network 97ce64ffdbSNiels Sascha Reedijk 98ce64ffdbSNiels Sascha Reedijk } // namespace BPrivate 99ce64ffdbSNiels Sascha Reedijk 100603e0bdfSNiels Sascha Reedijk #endif // _B_HTTP_HEADERS_H_ 101