1 #include "httpresponse.h"
3 HttpResponse::HttpResponse()
10 void HttpResponse::clear()
16 QByteArray HttpResponse::version() const
21 void HttpResponse::set_version(QByteArray const &ver)
26 int HttpResponse::status() const
31 void HttpResponse::set_status(int code)
36 int HttpResponse::index_of(QByteArray const &name) const
38 QByteArray name_ = name.toLower();
39 int j = m_attributes.size();
40 for(int i = 0; i < j; i++)
41 if(name_ == m_attributes.at(i).first.toLower()) return i;
44 bool HttpResponse::has_attribute(QByteArray const &name) const
46 QByteArray name_ = name.toLower();
47 for(pair_type const &pair : m_attributes)
48 if(name_ == pair.first.toLower()) return true;
52 QByteArray HttpResponse::attribute(QByteArray const& name) const
54 QByteArray name_ = name.toLower();
55 for(pair_type const &pair : m_attributes)
56 if(name_ == pair.first.toLower()) return pair.second;
61 void HttpResponse::set_attribute(QByteArray const &name, QByteArray const &value)
63 int i = index_of(name);
64 if(0 <= i) m_attributes.removeAt(i);
65 m_attributes.append(qMakePair(name, value));
68 void HttpResponse::set_attribute(QByteArray const &name, int value)
70 set_attribute(name, QByteArray::number(value));
73 int HttpResponse::content_length() const
75 int i = index_of("content-length");
76 if(0 <= i) return m_attributes.at(i).second.toInt();
80 char const* HttpResponse::status_string() const
84 case 100: return "100 Continue";
85 case 101: return "101 Switching Protocols";
87 case 200: return "200 OK";
88 case 201: return "201 Created";
89 case 202: return "202 Accepted";
90 case 203: return "203 Non-Authoritative Information";
91 case 204: return "204 No Content";
92 case 205: return "205 Reset Content";
93 case 206: return "206 Partial Content";
95 case 300: return "300 Multiple Choices";
96 case 301: return "301 Moved Permanently";
97 case 302: return "302 Found";
98 case 303: return "303 See Other";
99 case 304: return "304 Not Modified";
100 case 305: return "305 Use Proxy";
101 case 306: return "306 Unused";
102 case 307: return "307 Temporary Redirect";
104 case 400: return "400 Bad Request";
105 case 401: return "401 Unauthorized";
106 case 402: return "402 Payment Required";
107 case 403: return "403 Forbidden";
108 case 404: return "404 Not Found";
109 case 405: return "405 Method Not Allowed";
110 case 406: return "406 Not Acceptable";
111 case 407: return "407 Proxy Authentication Required";
112 case 408: return "408 Request Timeout";
113 case 409: return "409 Conflict";
114 case 410: return "410 Gone";
115 case 411: return "411 Length Required";
116 case 412: return "412 Precondition Failed";
117 case 413: return "413 Request Entity Too Large";
118 case 414: return "414 Request-Uri Too Long";
119 case 415: return "415 Unsupported Media Type";
120 case 416: return "416 Requested Range Not Satisfiable";
121 case 417: return "417 Expectation Failed";
123 case 500: return "500 Internal Server Error";
124 case 501: return "501 Not Implemented";
125 case 502: return "502 Bad Gateway";
126 case 503: return "503 Service Unavailable";
127 case 504: return "504 Gateway Timeout";
128 case 505: return "505 Http Version Not Supported";
134 QByteArray HttpResponse::to_latin_1() const
138 result.append("HTTP/").append(m_version).append(" ");
139 result.append(status_string()).append("\r\n");
141 for(pair_type const &pair : m_attributes)
142 result.append(pair.first).append(": ").append(pair.second).append("\r\n");
143 result.append("\r\n");