diff options
author | Tom Kunze <mail@tomabrafix.de> | 2021-08-01 23:12:36 +0200 |
---|---|---|
committer | Tom Kunze <mail@tomabrafix.de> | 2021-08-01 23:12:36 +0200 |
commit | 67600f75ff68bc2324ec025683066f0b691f619c (patch) | |
tree | e9a280a71989f4222f2699512f8c736dc8fbc229 /inc/HTTP/HTTPClient.php | |
parent | 1e519eb5339e02a75ee7aba2a1a5555f09ff8818 (diff) | |
download | dokuwiki-67600f75ff68bc2324ec025683066f0b691f619c.tar.gz dokuwiki-67600f75ff68bc2324ec025683066f0b691f619c.zip |
HTTPClient: Fix missing processing of redirections with status code 303, 307, 308.
HTTP/1.1 (RFC 7231) and RFC 7538 also define the redirection status codes 303,
307 and 308. These should be also supported as they are used more widely
nowadays (e.g. Google Docs).
Diffstat (limited to 'inc/HTTP/HTTPClient.php')
-rw-r--r-- | inc/HTTP/HTTPClient.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/inc/HTTP/HTTPClient.php b/inc/HTTP/HTTPClient.php index 3c0edf7ad..7ba95a7b6 100644 --- a/inc/HTTP/HTTPClient.php +++ b/inc/HTTP/HTTPClient.php @@ -168,6 +168,9 @@ class HTTPClient { $this->resp_body = ''; $this->resp_headers = array(); + // save unencoded data for recursive call + $unencodedData = $data; + // don't accept gzip if truncated bodies might occur if($this->max_bodysize && !$this->max_bodysize_abort && @@ -353,7 +356,7 @@ class HTTPClient { $this->debug('Object headers',$this->resp_headers); // check server status code to follow redirect - if($this->status == 301 || $this->status == 302 ){ + if(in_array($this->status, [301, 302, 303, 307, 308])){ if (empty($this->resp_headers['location'])){ throw new HTTPClientException('Redirect but no Location Header found'); }elseif($this->redirect_count == $this->max_redirect){ @@ -376,8 +379,13 @@ class HTTPClient { $this->resp_headers['location']; } } - // perform redirected request, always via GET (required by RFC) - return $this->sendRequest($this->resp_headers['location'],array(),'GET'); + if($this->status == 307 || $this->status == 308) { + // perform redirected request, same method as before (required by RFC) + return $this->sendRequest($this->resp_headers['location'],$unencodedData,$method); + }else{ + // perform redirected request, always via GET (required by RFC) + return $this->sendRequest($this->resp_headers['location'],array(),'GET'); + } } } |