-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
add http_client setBasicAuth #2542
Conversation
swoole_http_client_coro.cc
Outdated
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); | ||
|
||
std::string str = phc->get_basic_auth_encode(name, nameLen, passwd, passwdLen); | ||
zval *zheaders = sw_zend_read_property(swoole_http_client_coro_ce, getThis(), ZEND_STRL("requestHeaders"), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use sw_zend_read_property_array
, slient = 0
swoole_http_client_coro.cc
Outdated
@@ -1404,6 +1413,30 @@ bool http_client::close() | |||
return false; | |||
} | |||
|
|||
std::string http_client::get_basic_auth_encode(char *name, size_t nameLen, char *passwd, size_t passwdLen){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- code style (use snake name, put the brace on a new line)
- keep same with PHP API (
set_basic_auth
) or let it be a static function - use
emalloc
(this module has already been strongly associated with PHP) - why not using
sw_sprintf
?
swoole_http_client_coro.cc
Outdated
size_t outputLen = BASE64_ENCODE_OUT_SIZE(inputLen); | ||
char *input = new char[inputLen + 1]; | ||
char *output = new char[outputLen + 7]; | ||
if(input == nullptr || output == nullptr) return std::string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ will throw an exception instead of return nullptr
swoole_http_client_coro.cc
Outdated
static PHP_METHOD(swoole_http_client_coro, setBasicAuth) | ||
{ | ||
http_client* phc = swoole_get_phc(getThis()); | ||
char *name = nullptr, *passwd = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use snake name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For required parameters, initialization is not necessary
$pm = new ProcessManager; | ||
$pm->parentFunc = function ($pid) use ($pm) { | ||
go(function () use ($pm) { | ||
echo httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use http://httpbin.org (HTTPBIN_SERVER_HOST, HTTPBIN_SERVER_PORT), process manager is unnecessary
swoole_http_client_coro.cc
Outdated
zval *value = NULL; | ||
char *key; | ||
size_t keylen, keytype; | ||
if(Z_TYPE_P(zheaders) == IS_NULL) array_init(zheaders); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use php_array_merge
support http client setBasicAuth