From e131a21c6fc83328a4b3e9736ee8664dcbf8b332 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 28 May 2019 22:51:53 +0100 Subject: [PATCH] fix chained request support --- .../com/muwire/core/upload/UploadManager.groovy | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/upload/UploadManager.groovy b/core/src/main/groovy/com/muwire/core/upload/UploadManager.groovy index e74d6798..043c20e5 100644 --- a/core/src/main/groovy/com/muwire/core/upload/UploadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/UploadManager.groovy @@ -22,9 +22,21 @@ public class UploadManager { } public void processEndpoint(Endpoint e) throws IOException { + byte [] infoHashStringBytes = new byte[44] + DataInputStream dis = new DataInputStream(e.getInputStream()) + boolean first = true while(true) { - byte [] infoHashStringBytes = new byte[44] - DataInputStream dis = new DataInputStream(e.getInputStream()) + if (first) + first = false + else { + byte[] get = new byte[4] + dis.readFully(get) + if (get != "GET ".getBytes(StandardCharsets.US_ASCII)) { + log.warning("received a method other than GET on subsequent call") + e.close() + return + } + } dis.readFully(infoHashStringBytes) String infoHashString = new String(infoHashStringBytes, StandardCharsets.US_ASCII) log.info("Responding to upload request for root $infoHashString")