-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worker.java
executable file
·35 lines (32 loc) · 967 Bytes
/
Worker.java
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
import java.io.IOException;
import java.net.*;
import java.io.*;
public class Worker extends Thread{
Socket client;
MimeTypes mimeTypes;
HttpdConf httpdConf;
static Request request;
static ServerSocket socket;
static ResponseFactory responseFactory;
static Response response;
static Resource resource;
public Worker(HttpdConf httpdConf, MimeTypes mimeTypes, Socket socket){
client = socket;
this.mimeTypes = mimeTypes;
this.httpdConf = httpdConf;
}
public void run(){
System.out.println("Worker on socket: "+client);
try{
request = new Request(client.getInputStream());
resource = new Resource(request.getUriString(), httpdConf);
response = responseFactory.getResponse(request,resource,mimeTypes);
request.logRequest(httpdConf.logFile,response.code,response.size);
response.send(client.getOutputStream());
client.close();
}catch(Exception e){
System.out.println("Error"+client);
e.printStackTrace();
}
}
}