|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -287,35 +287,45 @@ public void run() {
|
287 | 287 | try {
|
288 | 288 | while(!stopped) {
|
289 | 289 | Socket clientConnection = ss.accept();
|
290 |
| - connections.add(clientConnection); |
291 | 290 | System.out.println(now() + getName() + ": Client accepted");
|
292 | 291 | StringBuilder headers = new StringBuilder();
|
293 |
| - Socket targetConnection = null; |
294 | 292 | InputStream ccis = clientConnection.getInputStream();
|
295 | 293 | OutputStream ccos = clientConnection.getOutputStream();
|
296 | 294 | Writer w = new OutputStreamWriter(
|
297 |
| - clientConnection.getOutputStream(), "UTF-8"); |
| 295 | + clientConnection.getOutputStream(), UTF_8); |
298 | 296 | PrintWriter pw = new PrintWriter(w);
|
299 | 297 | System.out.println(now() + getName() + ": Reading request line");
|
300 | 298 | String requestLine = readLine(ccis);
|
301 | 299 | System.out.println(now() + getName() + ": Request line: " + requestLine);
|
302 | 300 |
|
303 | 301 | StringTokenizer tokenizer = new StringTokenizer(requestLine);
|
304 | 302 | String method = tokenizer.nextToken();
|
305 |
| - assert method.equalsIgnoreCase("POST") |
306 |
| - || method.equalsIgnoreCase("GET"); |
| 303 | + if (!method.equals("GET") && !method.equals("POST")) { |
| 304 | + System.err.println(now() + getName() + ": Unexpected request method. Method: " + method); |
| 305 | + clientConnection.close(); |
| 306 | + continue; |
| 307 | + } |
| 308 | + |
307 | 309 | String path = tokenizer.nextToken();
|
| 310 | + if (!path.contains("/dummy/x")) { |
| 311 | + System.err.println(now() + getName() + ": Unexpected request path. Path: " + path); |
| 312 | + clientConnection.close(); |
| 313 | + continue; |
| 314 | + } |
| 315 | + |
308 | 316 | URI uri;
|
309 | 317 | try {
|
310 | 318 | String hostport = serverAuthority();
|
311 |
| - uri = new URI((secure ? "https" : "http") +"://" + hostport + path); |
| 319 | + uri = new URI((secure ? "https" : "http") + "://" + hostport + path); |
312 | 320 | } catch (Throwable x) {
|
313 |
| - System.err.printf("Bad target address: \"%s\" in \"%s\"%n", |
| 321 | + System.err.printf(now() + getName() + ": Bad target address: \"%s\" in \"%s\"%n", |
314 | 322 | path, requestLine);
|
315 | 323 | clientConnection.close();
|
316 | 324 | continue;
|
317 | 325 | }
|
318 | 326 |
|
| 327 | + // Method, path and URI are valid. Add to connections list |
| 328 | + connections.add(clientConnection); |
319 | 329 | // Read all headers until we find the empty line that
|
320 | 330 | // signals the end of all headers.
|
321 | 331 | String line = requestLine;
|
|
0 commit comments