Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

600611043 #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/
Assignments/HW1/DNWS/clientInfo.cs
6 changes: 5 additions & 1 deletion Assignments/HW1/DNWS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.IO;
using Microsoft.Extensions.Configuration;
using System.Threading;

namespace DNWS
{
Expand Down Expand Up @@ -287,8 +288,11 @@ public void Start()
// Get one, show some info
_parent.Log("Client accepted:" + clientSocket.RemoteEndPoint.ToString());
HTTPProcessor hp = new HTTPProcessor(clientSocket, _parent);
Thread thread = new Thread(new ThreadStart(hp.Process)); ////
thread.Start(); /////

// Single thread
hp.Process();
//hp.Process();
// End single therad

}
Expand Down
74 changes: 74 additions & 0 deletions Assignments/HW1/DNWS/client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DNWS
{
class client : IPlugin
{
protected static Dictionary<String, int> statDictionary = null;
public client()
{
if (statDictionary == null)
{
statDictionary = new Dictionary<String, int>();

}
}

public void PreProcessing(HTTPRequest request)
{
if (statDictionary.ContainsKey(request.Url))
{
statDictionary[request.Url] = (int)statDictionary[request.Url] + 1;
}
else
{
statDictionary[request.Url] = 1;
}
}
public HTTPResponse GetResponse(HTTPRequest request)
{
request.getPropertyByKey("RemoteEndPoint");
string _req = request.req;
HTTPResponse response = null;
StringBuilder sb = new StringBuilder();
string[] arr = _req.Split("User-Agent:");
string[] arr2 = arr[1].Split("Accept");
string[] arr3 = _req.Split("Accept-Encoding:");
string[] arr4 = arr3[1].Split("Accept");
string[] arr5 = _req.Split("Accept-Language:");
string[] port1 = request.getPropertyByKey("RemoteEndPoint").Split(":");
string[] port = request.getPropertyByKey("RemoteEndPoint").Split(":");
// string[] arr3 = _req.

sb.Append("<html><body><h1>Client IP : " +port[0] + "</h1>");
sb.Append("<html><body><h1>Port : " + port[1] + "</h1>");


sb.Append("<html><body><h1>Browser information : "+ arr2[0] +"</h1>");
foreach (KeyValuePair<String, int> entry in statDictionary)
{
sb.Append(entry.Key + ": " + entry.Value.ToString() + "<br />");
}



sb.Append("<html><body><h1>Accept-Language : " + arr5[1] + "</h1> <br>");

sb.Append("<html><body><h1>Accept-Encoding : " + arr4[0] + "</h1> <br>");


sb.Append("</body></html>");

response = new HTTPResponse(200);
response.body = Encoding.UTF8.GetBytes(sb.ToString());
return response;
}

public HTTPResponse PostProcessing(HTTPResponse response)
{
throw new NotImplementedException();
}
}
}
6 changes: 6 additions & 0 deletions Assignments/HW1/DNWS/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"Class" : "DNWS.OXPlugin",
"Preprocessing" : "false",
"Postprocessing" :"false"
},
{
"Path" : "client",
"Class" : "DNWS.clientInfo",
"Preprocessing" : "false",
"Postprocessing" :"false"
}
]
}