Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(http): improvement on http api #296

Merged
merged 9 commits into from
Aug 20, 2019
Merged

Conversation

neverchanje
Copy link
Contributor

The major improvements are the followings:

  • support empty table name on table_printer, so that http result on /recentStartTime are more readable.
    the old result is:
{
	"RecentStartTime": { //redundant
		"RecentStartTime": "2019-07-30 14:04:25"
	}
}

the new result is:

{
    "RecentStartTime": "2019-08-14 00:22:00"
}
  • support bool flag for http url query args, which is formerly required to be key-value pairs like 'arg=value&arg2=value2'. A user who wants to specify a bool flag must write ?arg=true, for example:
ip:port/meta/app?name=xxx&detail=true

Now, the url can be simplified to:

ip:port/meta/app?name=xxx&detail

@neverchanje neverchanje added the component/http HTTP/RESTful support label Aug 15, 2019
src/dist/http/http_server.cpp Outdated Show resolved Hide resolved
return error_s::make(ERR_INVALID_PARAMETERS, std::string("repeat parameters"));
ret.query_args.emplace(arg_vals[0], arg_vals[1]);
for (const std::string &arg_val : method_arg_val) {
size_t sep = arg_val.find_first_of('=');
Copy link
Member

Choose a reason for hiding this comment

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

感觉这种split类的操作在我们的项目中有好几种实现方式
这里是可以抽象出来, split出多个元素(1个,2个或多个可能是有不同的处理逻辑)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,之前引入 pprof 的时候还引入了 brpc 的 string_splitter,这个是相对 boost::split 性能更好的一种 split 写法,减少了内存拷贝,后面可以主推这种。但是在这里我们因为逻辑简单,杀鸡就不用牛刀了把。

@@ -47,7 +47,7 @@ class recent_start_time_http_service : public http_service
std::placeholders::_2));
}

std::string path() const override { return "startTime"; }
std::string path() const override { return "recentStartTime"; }
Copy link
Member

Choose a reason for hiding this comment

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

这里我觉得还是path作为一个http_service的成员变量比较好, 由基类返回就行了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

现在的写法在可靠性上问题不大,理解你的想法是每个 service 要写一个 path 函数比较麻烦?这个交给后面的重构做把。

{"http://127.0.0.1:34601?query1=value1", ERR_OK, {{"query1", "value1"}}},
{"http://127.0.0.1:34601?=", ERR_OK, {{"", ""}}},
{"http://127.0.0.1:34601?", ERR_OK, {}},

Copy link
Member

Choose a reason for hiding this comment

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

这些空行隐藏了什么特殊意义吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

没有,因为参数比较多,避免看花眼

@neverchanje neverchanje merged commit a9ab6c0 into XiaoMi:master Aug 20, 2019
@neverchanje neverchanje deleted the http branch August 20, 2019 02:51
@neverchanje neverchanje changed the title http: improvement on http api fix(http): improvement on http api Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component/http HTTP/RESTful support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants