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

Support RPC Transcoding for SRPCHttpServer #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

holmes1412
Copy link
Contributor

@holmes1412 holmes1412 commented Sep 2, 2024

Mentioned in this issue : #404

TODO:

  • Make the format formal and support trim for mapping string;
  • Add documents;

@holmes1412 holmes1412 changed the title Support service mapping for SRPCHttpServer Support RPC Transcoding for SRPCHttpServer Sep 3, 2024
@@ -248,26 +248,49 @@ static inline void __set_host_by_uri(const ParsedURI *uri, bool is_ssl,
}
}

static inline bool __set_request_uri_by_uri(const ParsedURI *uri,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里写成const ParsedURI& uri吧。这个类我们好像一般用引用。

Copy link
Contributor Author

@holmes1412 holmes1412 Sep 4, 2024

Choose a reason for hiding this comment

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

这个主要是用到task->get_current_uri()作为参数,由于返回到是指针,所以相应的内部函数就把参数也写成指针了。

src/rpc_server.h Outdated
const json_value_t *v;
std::string str;

val = json_value_parse(trans_coding);
Copy link
Contributor

Choose a reason for hiding this comment

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

这个val没有destroy吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的,漏了,已加。

SRPCHttpServer server;
ExampleServiceImpl impl;

server.add_service(&impl, "{ \"/test/echo\": \"Echo\","
Copy link
Contributor

Choose a reason for hiding this comment

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

这里用可以写多行的字符串吧。

src/rpc_server.h Outdated
@@ -49,6 +50,7 @@ class RPCServer : public WFServer<typename RPCTYPE::REQ,
RPCServer(const struct RPCServerParams *params);

int add_service(RPCService *service);
int add_service(RPCService *service, const char *trans_coding);
Copy link
Contributor

Choose a reason for hiding this comment

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

这里用const std::string& 吧。

@holmes1412
Copy link
Contributor Author

补充关于trans_code转换的描述,如何将 request_uri通过path_map查找到service和method。

1. initialization

server.add_service(my_example_service, '{ "/echo_a" : "Echo", "/echo_b" : "Echo"}');

这里会为server的path_map增加针对example_service的两个映射:

  • "/echo_a" -> "/Example/Echo"
  • "/echo_b" -> "/Example/Echo"

同时,为server的service_map增加一个查找service对象的映射(原有逻辑):

  • "/Example/Echo" -> my_example_service

2. query

  1. 如果是SRPCHttp:先把HTTP的request_uri(比如"/echo_a")通过path_map找到原始映射(比如"/Example/Echo"),设置到request_uri上;

  2. 继续走正常的server_process()流程,从request_uri拆'/'得出第一段(比如"/Example"),通过service_map查找出service对象,再调service对象的find_method()找后面部分对应的RPC函数。

@Barenboim Barenboim mentioned this pull request Oct 18, 2024
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.

2 participants