This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestParser { | |
static final int FIRST_ELEMENT = 0; | |
static final int SECOND_ELEMENT = 1; | |
static final int ELEMENTS_IN_REQUEST_LINE = 3; | |
static final String LINE_BREAK = "\\n"; | |
static final String EMPTY_SPACE = " "; | |
static final String COLON = ": "; | |
static final String AFTER_COLON = ":\\s"; | |
static final String EQUAL_SIGN = "="; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HashMap<String, String> getHeaders() { | |
return createTable(getMatchingStrings(); | |
} | |
private List<String> getMatchingStrings() { | |
List<String> headersStrings = new ArrayList<>(); | |
for (String string : splitRequest) { | |
if (string.contains(": ")) { | |
headersStrings.add(string); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Factory class | |
public class HandlerFactory { | |
private Request request; | |
private ResponseCodeBuilder responseCodeBuilder; | |
public HandlerFactory(Request request) { | |
this.request = request; | |
responseCodeBuilder = new ResponseCodeBuilder(request); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ServerMain { | |
static public void main (String args[]) throws IOException { | |
try { | |
ServerSocket server = new ServerSocket(5000); | |
while (true) { | |
Socket clientSocket = server.accept(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Params sent in the body of the request | |
POST / HTTP/1.1 | |
Host: example.com | |
Content-Type: application/x-www-form-urlencoded | |
a=3&b=2&c=1 | |
# Params sent in the URL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
script : http browser | |
set host : localhost | |
set port : 5000 | |
get : /form | |
ensure : response code equals 200 | |
reject : body has content data=fatcat | |
set data : data=fatcat | |
post : /form |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Request from Client | |
GET /path/file.html HTTP/1.0 | |
From: [email protected] | |
User-Agent: HTTPTool/1.0 | |
[blank line here] | |
# Response from Server | |
HTTP/1.0 200 OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / HTTP/1.1 | |
Host: localhost:5000 | |
Connection: keep-alive | |
Cache-Control: no-cache | |
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36 | |
Accept: */* | |
Accept-Encoding: gzip, deflate, sdch | |
Accept-Language: en-US,en;q=0.8 | |
Cookie: textwrapon=false; wysiwyg=textarea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EchoServer { | |
public static void main(String[] args) throws IOException { | |
try { | |
ServerSocket serverSocket = new ServerSocket(5000); | |
while (true) { | |
Socket clientSocket = serverSocket.accept(); | |
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EchoClient { | |
public static void main(String[] args) throws IOException { | |
if (args.length != 2) { | |
System.err.println("Usage: java EchoClient <host name> <port number>"); | |
System.exit(1); | |
} | |
String hostName = args[0]; | |
int portNumber = Integer.parseInt(args[1]); |