Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support to set the server bind address
Browse files Browse the repository at this point in the history
LinuxSuRen committed Mar 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9d12ce8 commit 024cc1c
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -31,12 +31,15 @@ public static void main(String[] args) {
// create the Options
Options options = new Options();
options.addOption("p", "port", true, "The cache server port");
options.addOption("", "bind", true, "The server bind address");

int port = 0;
String bind = null;
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);

bind = line.getOptionValue("bind", "0.0.0.0");
String portStr = line.getOptionValue("port", "" + defaultPort);

port = Integer.parseInt(portStr);
@@ -48,7 +51,7 @@ public static void main(String[] args) {
}

try {
new CacheServer().start(port);
new CacheServer().start(port, bind);
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -36,9 +36,9 @@ public class CacheServer implements HttpHandler {
private static int port = -1;
private Map<String, String> cacheQueue = new HashMap<>();

public void start(int port) throws IOException {
public void start(int port, String bind) throws IOException {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(20);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
InetSocketAddress address = new InetSocketAddress(bind, port);

Check failure on line 41 in src/main/java/listening/linuxsuren/github/io/server/CacheServer.java

Codacy Production / Codacy Static Code Analysis

src/main/java/listening/linuxsuren/github/io/server/CacheServer.java#L41

Server-Side-Request-Forgery (SSRF) exploits backend systems that initiate requests to third parties.
HttpServer server = HttpServer.create(address, 0);
server.setExecutor(threadPoolExecutor);
server.createContext("/", this);
@@ -48,7 +48,7 @@ public void start(int port) throws IOException {
}

public void start() throws IOException {
start(0);
start(0, "127.0.0.1");
}

private String getCacheDir() {

0 comments on commit 024cc1c

Please sign in to comment.