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