Put host extracting in its own method, handle URLs with the port explicitly specified (as long as it's 1965).
1 files changed, 17 insertions(+), 7 deletions(-)

M src/main/java/com/ajtjp/geminiclient/GeminiClient.java
M src/main/java/com/ajtjp/geminiclient/GeminiClient.java +17 -7
@@ 30,14 30,8 @@ public class GeminiClient {
         
         GeminiDocument doc = new GeminiDocument(url);
         
-//        String hardcodedURL = "rawtext.club";
 
-        int colonSlashSlashIndex = url.indexOf("://");
-        int endOfHost = url.indexOf("/", colonSlashSlashIndex + 3);
-        if (endOfHost == -1) {
-            endOfHost = url.length();
-        }
-        String host = url.substring(colonSlashSlashIndex + 3, endOfHost);
+        String host = extractHost(url);
 
         Socket s = basicSocketFactory.createSocket(host, port);
         s = sslSocketFactory.createSocket(s, host, port, true);

          
@@ 62,6 56,22 @@ public class GeminiClient {
         }
         
     }
+
+    private static String extractHost(String url) {
+        //        String hardcodedURL = "rawtext.club";
+        
+        int colonSlashSlashIndex = url.indexOf("://");
+        int colon = url.indexOf(":", colonSlashSlashIndex + 3);
+        if (colon != -1) {
+            return url.substring(colonSlashSlashIndex + 3, colon);
+        }
+        int endOfHost = url.indexOf("/", colonSlashSlashIndex + 3);
+        if (endOfHost == -1) {
+            endOfHost = url.length();
+        }
+        String host = url.substring(colonSlashSlashIndex + 3, endOfHost);
+        return host;
+    }
     
     private static String parseHeaders(InputStream is) throws IOException {
         //Max size is 1029 bytes, 1024 for meta + 2 for status + 3 for whitespace