Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
fix unit tests - changed order of header and response body
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakumo committed Feb 10, 2017
1 parent 4c02d11 commit 943c3e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/AwsInspector/Helper/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,30 @@ public function doRequest() {
// what's redirected to what curl alwyas seems to dump the headers last
$httpLine = false;
do {
$line = array_pop($result['output']);
// changed behaviour:
//
// result contains at the beginning the
// headers and after an empty line the response body.

$line = array_shift($result['output']);

if (empty($line)) {
$httpLine = true;
continue;
}

// yes, this is really ugly...
// I wish we'd be able to separate header and body in a cleaner way
// but we can't do this with exec(), and proc_open also doesn't make things easier
if (preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $line, $matches)) {
$this->setResponseCode($matches[0]);
$httpLine = true;

// put the rest back since it belongs to the response body
$restOfThatLine = preg_replace('|HTTP/\d\.\d\s+(\d+)\s+.*|', '', $line);
if ($restOfThatLine) {
array_push($result['output'], $restOfThatLine);
}
}
if (!$httpLine && !empty($line)) {
} elseif (!$httpLine && !empty($line)) {
$this->parseHeader($line);
}
} while(!$httpLine);
Expand Down

0 comments on commit 943c3e1

Please sign in to comment.