Skip to content

Commit

Permalink
Merge pull request #3516 from tomabrafix/fix-httpclient
Browse files Browse the repository at this point in the history
HTTPClient: Fix missing processing of redirections with status code 303, 307, 308.
  • Loading branch information
splitbrain committed Aug 2, 2021
2 parents 1e519eb + 67600f7 commit f0fb996
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions inc/HTTP/HTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public function sendRequest($url,$data='',$method='GET'){
$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 &&
Expand Down Expand Up @@ -353,7 +356,7 @@ public function sendRequest($url,$data='',$method='GET'){
$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){
Expand All @@ -376,8 +379,13 @@ public function sendRequest($url,$data='',$method='GET'){
$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');
}
}
}

Expand Down

0 comments on commit f0fb996

Please sign in to comment.