@@ -1254,13 +1254,8 @@ protected function _oauth2TokenNoCurl()
1254
1254
$ result .= "\r\n" . $ reply ;
1255
1255
1256
1256
// find HTTP status
1257
- $ httpstatus = '500 ' ;
1258
- $ match = [];
1259
- if (!empty ($ headers [0 ]) && preg_match ('/HTTP\/\d\.\d (\d{3})/ ' , $ headers [0 ], $ match )) {
1260
- $ httpstatus = $ match [1 ];
1261
- }
1262
-
1263
- $ reply = $ this ->_parseBearerReply ($ result , $ httpstatus );
1257
+ $ httpstatus = $ this ->_getHttpStatusFromHeaders ($ headers );
1258
+ $ reply = $ this ->_parseBearerReply ($ result , $ httpstatus );
1264
1259
return $ reply ;
1265
1260
}
1266
1261
@@ -1269,6 +1264,23 @@ protected function _oauth2TokenNoCurl()
1269
1264
* General helpers to avoid duplicate code
1270
1265
*/
1271
1266
1267
+ /**
1268
+ * Extract HTTP status code from headers
1269
+ *
1270
+ * @param array $headers The headers to parse
1271
+ *
1272
+ * @return string The HTTP status code
1273
+ */
1274
+ protected function _getHttpStatusFromHeaders ($ headers )
1275
+ {
1276
+ $ httpstatus = '500 ' ;
1277
+ $ match = [];
1278
+ if (!empty ($ headers [0 ]) && preg_match ('/HTTP\/\d\.\d (\d{3})/ ' , $ headers [0 ], $ match )) {
1279
+ $ httpstatus = $ match [1 ];
1280
+ }
1281
+ return $ httpstatus ;
1282
+ }
1283
+
1272
1284
/**
1273
1285
* Parse oauth2_token reply and set bearer token, if found
1274
1286
*
@@ -2095,12 +2107,7 @@ protected function _callApiNoCurl(
2095
2107
$ result .= "\r\n" . $ reply ;
2096
2108
2097
2109
// find HTTP status
2098
- $ httpstatus = '500 ' ;
2099
- $ match = [];
2100
- if (!empty ($ headers [0 ]) && preg_match ('/HTTP\/\d\.\d (\d{3})/ ' , $ headers [0 ], $ match )) {
2101
- $ httpstatus = $ match [1 ];
2102
- }
2103
-
2110
+ $ httpstatus = $ this ->_getHttpStatusFromHeaders ($ headers );
2104
2111
list ($ headers , $ reply ) = $ this ->_parseApiHeaders ($ result );
2105
2112
// TON API & redirects
2106
2113
$ reply = $ this ->_parseApiReplyPrefillHeaders ($ headers , $ reply );
@@ -2353,12 +2360,7 @@ protected function _callApiStreaming(
2353
2360
$ headers = explode ("\r\n" , $ result );
2354
2361
2355
2362
// find HTTP status
2356
- $ httpstatus = '500 ' ;
2357
- $ match = [];
2358
- if (!empty ($ headers [0 ]) && preg_match ('/HTTP\/\d\.\d (\d{3})/ ' , $ headers [0 ], $ match )) {
2359
- $ httpstatus = $ match [1 ];
2360
- }
2361
-
2363
+ $ httpstatus = $ this ->_getHttpStatusFromHeaders ($ headers );
2362
2364
list ($ headers ,) = $ this ->_parseApiHeaders ($ result );
2363
2365
$ rate = $ this ->_getRateLimitInfo ($ headers );
2364
2366
0 commit comments