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 14*ce64ffdbSNiels Sascha Reedijk #ifndef LIBNETAPI_DEPRECATED 15*ce64ffdbSNiels Sascha Reedijk namespace BPrivate { 16*ce64ffdbSNiels Sascha Reedijk 17*ce64ffdbSNiels Sascha Reedijk namespace Network { 18*ce64ffdbSNiels Sascha Reedijk #endif 19*ce64ffdbSNiels Sascha Reedijk 20603e0bdfSNiels Sascha Reedijk class BHttpHeader { 21603e0bdfSNiels Sascha Reedijk public: 22603e0bdfSNiels Sascha Reedijk BHttpHeader(); 23603e0bdfSNiels Sascha Reedijk BHttpHeader(const char* string); 24603e0bdfSNiels Sascha Reedijk BHttpHeader(const char* name, 25603e0bdfSNiels Sascha Reedijk const char* value); 26603e0bdfSNiels Sascha Reedijk BHttpHeader(const BHttpHeader& copy); 27603e0bdfSNiels Sascha Reedijk 28603e0bdfSNiels Sascha Reedijk // Header data modification 29603e0bdfSNiels Sascha Reedijk void SetName(const char* name); 30603e0bdfSNiels Sascha Reedijk void SetValue(const char* value); 31603e0bdfSNiels Sascha Reedijk bool SetHeader(const char* string); 32603e0bdfSNiels Sascha Reedijk 33603e0bdfSNiels Sascha Reedijk // Header data access 34603e0bdfSNiels Sascha Reedijk const char* Name() const; 35603e0bdfSNiels Sascha Reedijk const char* Value() const; 36603e0bdfSNiels Sascha Reedijk const char* Header() const; 37603e0bdfSNiels Sascha Reedijk 38603e0bdfSNiels Sascha Reedijk // Header data test 39603e0bdfSNiels Sascha Reedijk bool NameIs(const char* name) const; 40603e0bdfSNiels Sascha Reedijk 41603e0bdfSNiels Sascha Reedijk // Overloaded members 42603e0bdfSNiels Sascha Reedijk BHttpHeader& operator=(const BHttpHeader& other); 43603e0bdfSNiels Sascha Reedijk 44603e0bdfSNiels Sascha Reedijk private: 45603e0bdfSNiels Sascha Reedijk BString fName; 46603e0bdfSNiels Sascha Reedijk BString fValue; 47603e0bdfSNiels Sascha Reedijk 48603e0bdfSNiels Sascha Reedijk mutable BString fRawHeader; 49603e0bdfSNiels Sascha Reedijk mutable bool fRawHeaderValid; 50603e0bdfSNiels Sascha Reedijk }; 51603e0bdfSNiels Sascha Reedijk 52603e0bdfSNiels Sascha Reedijk 53603e0bdfSNiels Sascha Reedijk class BHttpHeaders { 54603e0bdfSNiels Sascha Reedijk public: 55603e0bdfSNiels Sascha Reedijk BHttpHeaders(); 56603e0bdfSNiels Sascha Reedijk BHttpHeaders(const BHttpHeaders& copy); 57603e0bdfSNiels Sascha Reedijk ~BHttpHeaders(); 58603e0bdfSNiels Sascha Reedijk 59603e0bdfSNiels Sascha Reedijk // Header list access 60603e0bdfSNiels Sascha Reedijk const char* HeaderValue(const char* name) const; 61603e0bdfSNiels Sascha Reedijk BHttpHeader& HeaderAt(int32 index) const; 62603e0bdfSNiels Sascha Reedijk 63603e0bdfSNiels Sascha Reedijk // Header count 64603e0bdfSNiels Sascha Reedijk int32 CountHeaders() const; 65603e0bdfSNiels Sascha Reedijk 66603e0bdfSNiels Sascha Reedijk // Header list tests 67603e0bdfSNiels Sascha Reedijk int32 HasHeader(const char* name) const; 68603e0bdfSNiels Sascha Reedijk 69603e0bdfSNiels Sascha Reedijk // Header add or replacement 70603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* line); 71603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* name, 72603e0bdfSNiels Sascha Reedijk const char* value); 73603e0bdfSNiels Sascha Reedijk bool AddHeader(const char* name, 74603e0bdfSNiels Sascha Reedijk int32 value); 75603e0bdfSNiels Sascha Reedijk 76603e0bdfSNiels Sascha Reedijk // Archiving 77603e0bdfSNiels Sascha Reedijk void PopulateFromArchive(BMessage*); 78603e0bdfSNiels Sascha Reedijk void Archive(BMessage*) const; 79603e0bdfSNiels Sascha Reedijk 80603e0bdfSNiels Sascha Reedijk // Header deletion 81603e0bdfSNiels Sascha Reedijk void Clear(); 82603e0bdfSNiels Sascha Reedijk 83603e0bdfSNiels Sascha Reedijk // Overloaded operators 84603e0bdfSNiels Sascha Reedijk BHttpHeaders& operator=(const BHttpHeaders& other); 85603e0bdfSNiels Sascha Reedijk BHttpHeader& operator[](int32 index) const; 86603e0bdfSNiels Sascha Reedijk const char* operator[](const char* name) const; 87603e0bdfSNiels Sascha Reedijk 88603e0bdfSNiels Sascha Reedijk private: 89603e0bdfSNiels Sascha Reedijk void _EraseData(); 90603e0bdfSNiels Sascha Reedijk bool _AddOrDeleteHeader(BHttpHeader* header); 91603e0bdfSNiels Sascha Reedijk 92603e0bdfSNiels Sascha Reedijk private: 93603e0bdfSNiels Sascha Reedijk BList fHeaderList; 94603e0bdfSNiels Sascha Reedijk }; 95603e0bdfSNiels Sascha Reedijk 96*ce64ffdbSNiels Sascha Reedijk #ifndef LIBNETAPI_DEPRECATED 97*ce64ffdbSNiels Sascha Reedijk } // namespace Network 98*ce64ffdbSNiels Sascha Reedijk 99*ce64ffdbSNiels Sascha Reedijk } // namespace BPrivate 100*ce64ffdbSNiels Sascha Reedijk #endif 101*ce64ffdbSNiels Sascha Reedijk 102603e0bdfSNiels Sascha Reedijk #endif // _B_HTTP_HEADERS_H_ 103