ffead.server.doc
HttpResponse.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * HttpResponse.h
18  *
19  * Created on: Aug 19, 2009
20  * Author: sumeet
21  */
22 
23 #ifndef HTTPRESPONSE_H_
24 #define HTTPRESPONSE_H_
25 #include "string"
26 #include "vector"
27 #include "CastUtil.h"
28 #include "HttpRequest.h"
29 #include "AppDefines.h"
30 #include "HTTPResponseStatus.h"
31 #include "ContentTypes.h"
32 using namespace std;
33 typedef vector<unsigned char> Cont;
34 class HttpResponse {
35 public:
36  HttpResponse();
37  virtual ~HttpResponse();
38  string getContent_str() const
39  {
40  return content_str;
41  }
42 
43  void setContent_str(string content_str)
44  {
45  this->content_str = content_str;
46  //this->content_len = CastUtil::lexical_cast<string>(content_str.length());
47  }
48 
49  string getHttpVersion() const
50  {
51  return httpVersion;
52  }
53 
54  void setHttpVersion(string httpVersion)
55  {
56  this->httpVersion = httpVersion;
57  }
58 
59  void setHTTPResponseStatus(HTTPResponseStatus status)
60  {
61  this->statusCode = CastUtil::lexical_cast<string>(status.getCode());
62  this->statusMsg = status.getMsg();
63  }
64 
65  string getStatusCode() const
66  {
67  return statusCode;
68  }
69 
70  void setStatusCode(string statusCode)
71  {
72  this->statusCode = statusCode;
73  }
74 
75  string getStatusMsg() const
76  {
77  return statusMsg;
78  }
79 
80  void setStatusMsg(string statusMsg)
81  {
82  this->statusMsg = statusMsg;
83  }
84 
85  string getDate() const
86  {
87  return date;
88  }
89 
90  void setDate(string date)
91  {
92  this->date = date;
93  }
94 
95  string getConnection() const
96  {
97  return connection;
98  }
99 
100  void setConnection(string connection)
101  {
102  this->connection = connection;
103  }
104 
105  string getServer() const
106  {
107  return server;
108  }
109 
110  void setServer(string server)
111  {
112  this->server = server;
113  }
114 
115  string getAccept_ranges() const
116  {
117  return accept_ranges;
118  }
119 
120  void setAccept_ranges(string accept_ranges)
121  {
122  this->accept_ranges = accept_ranges;
123  }
124 
125  string getContent_type() const
126  {
127  return content_type;
128  }
129 
130  void setContent_type(string content_type)
131  {
132  this->content_type = content_type;
133  }
134 
135  int getContent_len() const
136  {
137  return content_str.length();
138  }
139 
140  /*void setContent_len(string content_len)
141  {
142  this->content_len = content_len;
143  }*/
144 
145  string getContent() const
146  {
147  return content_str;
148  }
149 
150  /*void setContent(Cont content)
151  {
152  this->content_str = content_str;
153  this->content_len = CastUtil::lexical_cast<string>(content_str.length());
154  }*/
155 
156  void setContent(string content)
157  {
158  this->content_str = content_str;
159  //this->content_len = CastUtil::lexical_cast<string>(content_str.length());
160  }
161 
162  string getLast_modified() const
163  {
164  return last_modified;
165  }
166 
167  void setLast_modified(string last_modified)
168  {
169  this->last_modified = last_modified;
170  }
171 
172  string getLocation() const
173  {
174  return location;
175  }
176  void setLocation(string location)
177  {
178  this->location = location;
179  }
180 
181  string getWww_authenticate() const
182  {
183  return www_authenticate;
184  }
185  void setWww_authenticate(string www_authenticate)
186  {
187  this->www_authenticate = www_authenticate;
188  }
189 
190  void addCookie(string cookie)
191  {
192  this->cookies.push_back(cookie);
193  }
194 
195  string generateResponse();
196  string generateHeadResponse();
197  string generateOptionsResponse();
198  string generateTraceResponse(HttpRequest* req);
199 private:
200  string httpVersion;
201  string statusCode;
202  string statusMsg;
203  string date;
204  string connection;
205  string server;
206  string accept_ranges;
207  Cont content;
208  string content_type;
209  //string content_len;
210  string last_modified;
211  string content_str;
212  string location;
213  vector<string> cookies;
214  string www_authenticate;
215 };
216 
217 #endif /* HTTPRESPONSE_H_ */