1 // ***************************************************************************
2 // HttpHeader_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 November 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides a generic interface for parsing/generating HTTP headers, along
8 // with specialized request & response header types
9 // ***************************************************************************
11 #ifndef HTTP_HEADER_P_H
12 #define HTTP_HEADER_P_H
18 // This file is not part of the BamTools API. It exists purely as an
19 // implementation detail. This header file may change from version to version
20 // without notice, or even be removed.
24 #include "api/api_global.h"
36 HttpHeader(const std::string& s);
37 virtual ~HttpHeader(void);
39 // HttpHeader interface
42 // header field=>value access
43 bool ContainsKey(const std::string& key) const;
44 std::string GetValue(const std::string& key) const;
45 void RemoveField(const std::string& key);
46 void SetField(const std::string& key, const std::string& value);
48 // get formatted header string
49 virtual std::string ToString(void) const;
51 // query HTTP version used
52 int GetMajorVersion(void) const;
53 int GetMinorVersion(void) const;
55 // see if header was parsed OK
56 bool IsValid(void) const;
60 void Parse(const std::string& s);
61 virtual bool ParseLine(const std::string& line, int lineNumber);
62 void SetValid(bool ok);
63 void SetVersion(int major, int minor);
67 std::map<std::string, std::string> m_fields;
69 bool m_isValid; // should usually be true, only false if error processing a header line
74 class HttpRequestHeader : public HttpHeader {
78 HttpRequestHeader(const std::string& method, // "GET", "PUT", etc
79 const std::string& resource, // filename
80 int majorVersion = 1, // version info
81 int minorVersion = 1);
82 ~HttpRequestHeader(void);
84 // HttpRequestHeader interface
86 std::string GetMethod(void) const;
87 std::string GetResource(void) const;
89 // HttpHeader implementation
91 std::string ToString(void) const;
93 bool ParseLine(const std::string& line, int lineNumber);
98 std::string m_resource;
101 class HttpResponseHeader : public HttpHeader {
105 HttpResponseHeader(const int statusCode, // 200, 404, etc
106 const std::string& reason = std::string(), // 'reason phrase' for code
107 int majorVersion = 1, // version info
108 int minorVersion = 1);
109 HttpResponseHeader(const std::string& s);
110 ~HttpResponseHeader(void);
112 // HttpRequestHeader interface
114 std::string GetReason(void) const;
115 int GetStatusCode(void) const;
117 // HttpHeader implementation
119 std::string ToString(void) const;
121 bool ParseLine(const std::string& line, int lineNumber);
126 std::string m_reason;
129 } // namespace Internal
130 } // namespace BamTools
132 #endif // HTTP_HEADER_P_H