forked from CharlZKP/CPE433-62
-
Notifications
You must be signed in to change notification settings - Fork 34
/
DelayPlugin.cs
50 lines (45 loc) · 1.22 KB
/
DelayPlugin.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace DNWS
{
class DelayPlugin : IPlugin
{
public DelayPlugin()
{
}
public void PreProcessing(HTTPRequest request)
{
throw new NotImplementedException();
}
public HTTPResponse GetResponse(HTTPRequest request)
{
HTTPResponse response = null;
String[] parts = Regex.Split(request.Filename, "[?]");
Int32 delay = 0;
if (parts.Length > 1) {
try {
delay = Convert.ToInt32(parts[1]);
} catch (Exception ex) {
response = new HTTPResponse(400);
response.body = Encoding.UTF8.GetBytes(ex.ToString());
return response;
}
}
StringBuilder sb = new StringBuilder();
response = new HTTPResponse(200);
Thread.Sleep(delay);
sb.Append("<html><body>");
sb.Append("<h1>Sleep for " + delay + " millisecond. </h1>");
sb.Append("</body></html>");
response.body = Encoding.UTF8.GetBytes(sb.ToString());
return response;
}
public HTTPResponse PostProcessing(HTTPResponse response)
{
throw new NotImplementedException();
}
}
}