This file contains 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
distributions { | |
main { | |
contents { | |
from 'server', { | |
into 'bin/server' | |
} | |
} | |
} | |
} |
This file contains 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 void run() { | |
OutputStream dataOut = null; | |
try (BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); | |
PrintWriter out = new PrintWriter(client.getOutputStream())) { | |
Map<String, String> requestHeaders = parseRequestHeaders(in); | |
String method = requestHeaders.get(METHOD); |
This file contains 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
private Map<String, String> parseRequestHeaders(BufferedReader in) throws IOException { | |
Map<String, String> headers = new HashMap<>(); | |
// parse the first line. | |
String header = in.readLine(); | |
StringTokenizer tokenizer = new StringTokenizer(header); | |
headers.put(METHOD, tokenizer.nextToken().toUpperCase()); | |
headers.put(RESOURCE, tokenizer.nextToken().toLowerCase()); | |
headers.put(PROTOCOL, tokenizer.nextToken()); | |
// Rest of the headers | |
String line; |
This file contains 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
private String resolveResource(String requestedPath) { | |
Path resolvedPath = FileSystems.getDefault().getPath(""); | |
Path other = FileSystems.getDefault().getPath(requestedPath); | |
for (Path path : other) { | |
if (!path.startsWith(".") && !path.startsWith("..")) { | |
resolvedPath = resolvedPath.resolve(path); | |
} | |
} | |
if (resolvedPath.startsWith("")) { | |
resolvedPath = resolvedPath.resolve(INDEX_HTML); |
This file contains 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
private Map<String, String> parseRequestHeaders(BufferedReader in) throws IOException { | |
Map<String, String> headers = new HashMap<>(); | |
String line; | |
while ((line = in.readLine()) != null && !line.isEmpty()) { | |
int idx = line.indexOf(':'); | |
if (idx > 0) { | |
headers.put(line.substring(0, idx).toLowerCase(), line.substring(idx + 1).trim()); | |
} | |
} | |
return headers; |
This file contains 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
package blog.devrandom.http; | |
import java.io.BufferedOutputStream; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.ServerSocket; |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Not Implemented</title> | |
</head> | |
<body> | |
<h1>Not Implemented</h1> | |
</body> | |
</html> |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Not Found</title> | |
</head> | |
<body> | |
<h1>Resource not found on this server.</h1> | |
</body> | |
</html> |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Home page</title> | |
</head> | |
<body> | |
<h1>Simple Java HTTP server</h1> | |
<p>This is the home page.</p> | |
</body> |
This file contains 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
<div | |
:aria-expanded="[isOpen ? 'true' : 'false']" | |
:aria-owns="'lbox_' + _uid" | |
:class="['select__dropdown', isOpen ? 'select__dropdown--open' : 'select__dropdown--close']" | |
@click="toggle" | |
@keyup.space="toggle" | |
@keyup.up="moveUp" | |
@keyup.down="moveDown" | |
@keyup.enter="selectFromKeyboard" | |
aria-autocomplete="none" |
NewerOlder