@@ -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