Skip to content

Commit e4bef10

Browse files
committed
Moved response sending after connection has been established (#225) + updated zeroconf-java
1 parent 11a591c commit e4bef10

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<dependency>
7272
<groupId>xyz.gianlu.zeroconf</groupId>
7373
<artifactId>zeroconf</artifactId>
74-
<version>1.1.2</version>
74+
<version>1.1.3</version>
7575
</dependency>
7676

7777
<!-- HTTP -->

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,6 @@ private void handleAddUser(OutputStream out, Map<String, String> params, String
305305
aes.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Arrays.copyOfRange(encryptionKey, 0, 16), "AES"), new IvParameterSpec(iv));
306306
byte[] decrypted = aes.doFinal(encrypted);
307307

308-
309-
String resp = DEFAULT_SUCCESSFUL_ADD_USER.toString();
310-
out.write(httpVersion.getBytes());
311-
out.write(" 200 OK".getBytes());
312-
out.write(EOL);
313-
out.write("Content-Length: ".getBytes());
314-
out.write(String.valueOf(resp.length()).getBytes());
315-
out.write(EOL);
316-
out.flush();
317-
318-
out.write(EOL);
319-
out.write(resp.getBytes());
320-
out.flush();
321-
322-
323308
try {
324309
Authentication.LoginCredentials credentials = inner.decryptBlob(username, decrypted);
325310

@@ -330,9 +315,28 @@ private void handleAddUser(OutputStream out, Map<String, String> params, String
330315
session.authenticate(credentials);
331316

332317
sessionListeners.forEach(l -> l.sessionChanged(session));
318+
319+
// Sending response
320+
String resp = DEFAULT_SUCCESSFUL_ADD_USER.toString();
321+
out.write(httpVersion.getBytes());
322+
out.write(" 200 OK".getBytes());
323+
out.write(EOL);
324+
out.write("Content-Length: ".getBytes());
325+
out.write(String.valueOf(resp.length()).getBytes());
326+
out.write(EOL);
327+
out.flush();
328+
329+
out.write(EOL);
330+
out.write(resp.getBytes());
331+
out.flush();
333332
} catch (Session.SpotifyAuthenticationException | MercuryClient.MercuryException ex) {
334-
LOGGER.fatal("Failed handling connection! Going away.", ex);
335-
close();
333+
LOGGER.fatal("Couldn't establish a new session.", ex);
334+
335+
out.write(httpVersion.getBytes());
336+
out.write(" 500 Internal Server Error".getBytes()); // I don't think this is the Spotify way
337+
out.write(EOL);
338+
out.write(EOL);
339+
out.flush();
336340
}
337341
}
338342

0 commit comments

Comments
 (0)