[BUG] HTTPSocket doesn't follow redirects properly

teo

New member
Joined
Aug 30, 2021
Messages
4
HTTPSocket doesn’t follow redirects properly
1. Add https default port (443) if no custom port is specified in the redirect URL
2. Forward basic auth data if nothing else is specified in the redirect URL - maybe an option/param should be added
3. Default query to an empty string if not available

- https://files.directadmin.com/services/all/httpsocket/
- httpsocket.php.3.0.4 | 11-Jan-2021 22:04

These are the changes we did but would be great to not have customizations and rely on the provided code.
PHP:
diff --git a/lib/HTTPSocket.php b/lib/HTTPSocket.php
index ca926df..23c8387 100644
--- a/lib/HTTPSocket.php
+++ b/lib/HTTPSocket.php
@@ -166,15 +166,18 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
             $location = parse_url($request);
             if (preg_match('!^https://!i',$request))
             {
-                $this->connect('https://'.$location['host'],$location['port']);
+                // use https default port if no custom port is specified in the redirect URL
+                $this->connect('https://'.$location['host'],$location['port'] ?? 443);
             }
             else
                 $this->connect('http://'.$location['host'],$location['port']);
 
-            $this->set_login($location['user'],$location['pass']);
+            // forward basic auth data if nothing else is specified in the redirect URL
+            $this->set_login($location['user'] ?? $this->remote_uname,$location['pass'] ?? $this->remote_passwd);
 
             $request = $location['path'];
-            $content = $location['query'];
+            // default to an empty string if not available
+            $content = $location['query'] ?? '';
 
             if ( strlen($request) < 1 )
             {
 
Back
Top