Skip to content

Commit

Permalink
Merge pull request #36 from erelke/2.x
Browse files Browse the repository at this point in the history
extend getLastRequestData, remove Expect header
  • Loading branch information
pzs authored Nov 26, 2020
2 parents 23979a1 + a9018c7 commit 4cf5edc
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/NavOnlineInvoice/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Connector {
protected $config;

private $lastRequestUrl = null;
private $lastRequestHeader = null;
private $lastRequestBody = null;
private $lastResponseHeader = null;
private $lastResponseBody = null;
private $lastRequestId = null;

Expand All @@ -24,7 +26,9 @@ function __construct($config) {

private function resetDebugInfo() {
$this->lastRequestUrl = null;
$this->lastRequestHeader = null;
$this->lastRequestBody = null;
$this->lastResponseHeader = null;
$this->lastResponseBody = null;
$this->lastRequestId = null;
}
Expand All @@ -38,7 +42,9 @@ private function resetDebugInfo() {
public function getLastRequestData() {
return array(
'requestUrl' => $this->lastRequestUrl,
'requestHeader' => $this->lastRequestHeader,
'requestBody' => $this->lastRequestBody,
'responseHeader' => $this->lastResponseHeader,
'responseBody' => $this->lastResponseBody,
'lastRequestId' => $this->lastRequestId,
);
Expand Down Expand Up @@ -72,11 +78,16 @@ public function post($url, $requestXml) {

$ch = $this->getCurlHandle($url, $xmlString);

$result = curl_exec($ch);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$info = curl_getinfo($ch);
$header = substr($response, 0, $info["header_size"]);
$result = substr($response, $info["header_size"]);

$httpStatusCode = $info["http_code"];

$this->lastRequestHeader = $info["request_header"];
$this->lastResponseHeader = $header;
$this->lastResponseBody = $result;

curl_close($ch);
Expand Down Expand Up @@ -118,10 +129,19 @@ private function getCurlHandle($url, $requestBody) {
$ch = curl_init($url);

$headers = array(
"Content-Type: application/xml;charset=\"UTF-8\"",
"Accept: application/xml"
"Content-Type: application/xml;charset=UTF-8",
"Accept: application/xml",
);

$curl_version = curl_version();

if (version_compare($curl_version['version'], '7.69') < 0) {
$headers[] = "Expect:";
//ha eredeti értékét megtartjuk, akkor NAV üres body-t add vissza nagy méretű válaszok esetén
//@see https://daniel.haxx.se/blog/2020/02/27/expect-tweaks-in-curl/
//(cURL <7.69)
}

$verifySSL = isset($this->config->verifySLL) ? $this->config->verifySLL : $this->config->verifySSL;

if (!$verifySSL) {
Expand All @@ -134,6 +154,9 @@ private function getCurlHandle($url, $requestBody) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

if ($this->config->curlTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
Expand Down

0 comments on commit 4cf5edc

Please sign in to comment.