Skip to content

Commit 0b5b81a

Browse files
committed
Minor clean up
1 parent 8f9d3df commit 0b5b81a

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/core/ZeroconfAuthenticator.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,8 @@ private class HttpRunner implements Runnable, Closeable {
250250
@Override
251251
public void run() {
252252
while (!shouldStop) {
253-
try {
254-
try (Socket socket = serverSocket.accept()) { // We don't need this to be async
255-
handle(socket);
256-
}
253+
try (Socket socket = serverSocket.accept()) { // We don't need this to be async
254+
handle(socket);
257255
} catch (IOException ex) {
258256
LOGGER.fatal("Failed handling request!", ex);
259257
}
@@ -267,24 +265,23 @@ private void handle(@NotNull Socket socket) throws IOException {
267265
String[] requestLine = Utils.split(Utils.readLine(in), ' ');
268266
if (requestLine.length != 3) {
269267
LOGGER.warn("Unexpected request line: " + Arrays.toString(requestLine));
270-
socket.close();
271268
return;
272269
}
273270

274271
String method = requestLine[0];
275272
String path = requestLine[1];
276273
String httpVersion = requestLine[2];
277-
LOGGER.trace(String.format("Handling request: %s %s %s", method, path, httpVersion));
278274

279-
if (method.equals("POST") && path.equals("/")) {
280-
Map<String, String> headers = new HashMap<>(7);
275+
Map<String, String> headers = new HashMap<>();
276+
String header;
277+
while (!(header = Utils.readLine(in)).isEmpty()) {
278+
String[] split = Utils.split(header, ':');
279+
headers.put(split[0], split[1].trim());
280+
}
281281

282-
String header;
283-
while (!(header = Utils.readLine(in)).isEmpty()) {
284-
String[] split = Utils.split(header, ':');
285-
headers.put(split[0], split[1].trim());
286-
}
282+
LOGGER.trace(String.format("Handling request: %s %s %s, headers: %s", method, path, httpVersion, headers));
287283

284+
if (method.equals("POST") && path.equals("/")) {
288285
String contentType = headers.get("Content-Type");
289286
if (!Objects.equals(contentType, "application/x-www-form-urlencoded")) {
290287
LOGGER.fatal("Bad Content-Type: " + contentType);

0 commit comments

Comments
 (0)