Skip to content
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

Merged
merged 3 commits into from
May 5, 2019
Merged

add http_client setBasicAuth #2542

merged 3 commits into from
May 5, 2019

Conversation

hongbshi
Copy link

support http client setBasicAuth

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);
Copy link
Member

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

@@ -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){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. code style (use snake name, put the brace on a new line)
  2. keep same with PHP API (set_basic_auth) or let it be a static function
  3. use emalloc (this module has already been strongly associated with PHP)
  4. why not using sw_sprintf?

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();
Copy link
Member

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

static PHP_METHOD(swoole_http_client_coro, setBasicAuth)
{
http_client* phc = swoole_get_phc(getThis());
char *name = nullptr, *passwd = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use snake name

Copy link
Member

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()}/");
Copy link
Member

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

zval *value = NULL;
char *key;
size_t keylen, keytype;
if(Z_TYPE_P(zheaders) == IS_NULL) array_init(zheaders);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use php_array_merge

@matyhtf matyhtf merged commit 6941205 into swoole:master May 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants