-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHttpResponse.cpp
51 lines (46 loc) · 1.48 KB
/
HttpResponse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @file
* @copyright Copyright © 2014 by Marc Sibert
* @author Marc Sibert
*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file or http://www.wtfpl.net/
* for more details.
*/
#include "HttpResponse.h"
const char* const HttpResponse::DEFAULT_CONTENT_TYPE = "Content-Type: text/html; charset=utf-8";
void operator<<(Stream& aStream, const HttpResponse& aResponse) {
aStream.print("http/1.1 ");
aStream.print(aResponse.fStatus);
switch (aResponse.fStatus) {
case 200 :
aStream.print(" OK\r\n");
break;
case 404 :
aStream.print(" Not Found\r\n");
break;
default :
aStream.print(" \r\n");
break;
}
if (aResponse.fContentType) {
aStream.print("Content-Type:");
aStream.print(aResponse.fContentType);
aStream.print("\r\n");
}
if (aResponse.fContentLength >= 0) {
aStream.print("Content-Length:");
aStream.print(aResponse.fContentLength);
aStream.print("\r\n");
}
aStream.print("Server: MServer 0.1\r\n");
aStream.print("Connection: close\r\n");
aStream.print("\r\n");
aResponse.printBody(aStream);
}
/**
* Global defined err204 : HTTP 204 No Content.
* Note : using this status, "the client SHOULD NOT change its document view..."
*/
Err204 err204;