btcpayserver / btcpayserver-php-client

PHP implementation for the BTCPayServer cryptographically secure RESTful API
MIT License
29 stars 33 forks source link

createInvoice() HTTP/2 breaks expected response #14

Closed klokit-co closed 5 years ago

klokit-co commented 5 years ago

My production server is throwing the following error when attempting to create an invoice.

"Notice: Undefined offset: 2 in btcpayserver-php-client/src/BTCPayServer/Client/Response.php on line 76"

Line 76 is breaking when trying to interpret the first line of the response, which is : "0 = HTTP/2 200"

$response->setStatusCode($statusCode = $statusLine[2];

$statusLine[2] is (supposed to be being) initialised by the preceding line :

preg_match('/^HTTP\/(\d.\d)\s(\d+)\s(.+)/', $lines[$i], $statusLine);

It is that line that is trying to parse "0 = HTTP/2 200".

Obviously there's something in the format of the supplied string that is breaking the patterns being searched for in preg_match()

For now, I am using the following workaround.

if(strstr($lines[$i],'HTTP/2 200')) $lines[$i] = str_replace('HTTP/2 200','HTTP/2.1 200 OK',$lines[$i]);

NicolasDorier commented 5 years ago

Can you test https://github.com/btcpayserver/btcpayserver-php-client/pull/11 and let us know?