| 224 | } |
| 225 | |
| 226 | string Response::to_string() const { |
| 227 | string result; |
| 228 | |
| 229 | // Status line |
| 230 | result += "HTTP/1.0 "; |
| 231 | result += fl::to_string(mStatusCode); |
| 232 | result += " "; |
| 233 | result += status_text(mStatusCode); |
| 234 | result += "\r\n"; |
| 235 | |
| 236 | // Headers |
| 237 | for (auto it = mHeaders.begin(); it != mHeaders.end(); ++it) { |
| 238 | result += it->first + ": " + it->second + "\r\n"; |
| 239 | } |
| 240 | |
| 241 | // Content-Length (auto-calculated) |
| 242 | result += "Content-Length: " + fl::to_string(mBody.size()) + "\r\n"; |
| 243 | |
| 244 | // End of headers |
| 245 | result += "\r\n"; |
| 246 | |
| 247 | // Body |
| 248 | result += mBody; |
| 249 | |
| 250 | return result; |
| 251 | } |
| 252 | |
| 253 | //============================================================================== |
| 254 | // HttpServer implementation |
no test coverage detected