forked from CharlZKP/CPE433-62
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathHTTPResponse.cs
76 lines (68 loc) · 2.07 KB
/
HTTPResponse.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DNWS
{
// RFC1945
public class HTTPResponse
{
protected int _status = 404;
public int status
{
get { return _status; }
set { _status = value; }
}
protected byte[] _body;
public byte[] body
{
get { return _body; }
set { _body = value; }
}
protected string _type = "text/html";
public string type
{
get { return _type; }
set { _type = value; }
}
public String header
{
get
{
StringBuilder headerResponse = new StringBuilder("HTTP/1.0 ");
switch (_status)
{
case 200:
headerResponse.Append("200 OK");
break;
case 400:
headerResponse.Append("400 Bad Request");
break;
case 403:
headerResponse.Append("403 Forbidden");
break;
case 404:
headerResponse.Append("404 Not Found");
break;
case 500:
headerResponse.Append("500 Internal Server Error");
break;
case 501:
headerResponse.Append("501 Not Implemented");
break;
}
headerResponse.Append("\r\n");
headerResponse.Append("Content-Type: ").Append(type).Append("\r\n");
headerResponse.Append("Connection: close\r\n");
headerResponse.Append("Server: DNWS 1.0\r\n");
headerResponse.Append("\r\n");
return headerResponse.ToString();
}
}
public HTTPResponse(int status)
{
_status = status;
}
}
}