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 <Message.h> 11 #include <String.h> 12 13 14 #ifndef LIBNETAPI_DEPRECATED 15 namespace BPrivate { 16 17 namespace Network { 18 #endif 19 20 class BHttpHeader { 21 public: 22 BHttpHeader(); 23 BHttpHeader(const char* string); 24 BHttpHeader(const char* name, 25 const char* value); 26 BHttpHeader(const BHttpHeader& copy); 27 28 // Header data modification 29 void SetName(const char* name); 30 void SetValue(const char* value); 31 bool SetHeader(const char* string); 32 33 // Header data access 34 const char* Name() const; 35 const char* Value() const; 36 const char* Header() const; 37 38 // Header data test 39 bool NameIs(const char* name) const; 40 41 // Overloaded members 42 BHttpHeader& operator=(const BHttpHeader& other); 43 44 private: 45 BString fName; 46 BString fValue; 47 48 mutable BString fRawHeader; 49 mutable bool fRawHeaderValid; 50 }; 51 52 53 class BHttpHeaders { 54 public: 55 BHttpHeaders(); 56 BHttpHeaders(const BHttpHeaders& copy); 57 ~BHttpHeaders(); 58 59 // Header list access 60 const char* HeaderValue(const char* name) const; 61 BHttpHeader& HeaderAt(int32 index) const; 62 63 // Header count 64 int32 CountHeaders() const; 65 66 // Header list tests 67 int32 HasHeader(const char* name) const; 68 69 // Header add or replacement 70 bool AddHeader(const char* line); 71 bool AddHeader(const char* name, 72 const char* value); 73 bool AddHeader(const char* name, 74 int32 value); 75 76 // Archiving 77 void PopulateFromArchive(BMessage*); 78 void Archive(BMessage*) const; 79 80 // Header deletion 81 void Clear(); 82 83 // Overloaded operators 84 BHttpHeaders& operator=(const BHttpHeaders& other); 85 BHttpHeader& operator[](int32 index) const; 86 const char* operator[](const char* name) const; 87 88 private: 89 void _EraseData(); 90 bool _AddOrDeleteHeader(BHttpHeader* header); 91 92 private: 93 BList fHeaderList; 94 }; 95 96 #ifndef LIBNETAPI_DEPRECATED 97 } // namespace Network 98 99 } // namespace BPrivate 100 #endif 101 102 #endif // _B_HTTP_HEADERS_H_ 103