Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPClient: Fix missing processing of redirections with status code 303, 307, 308. #3516

Merged
merged 1 commit into from
Aug 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions inc/HTTP/HTTPClient.php
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