Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
633d8a3c
Commit
633d8a3c
authored
Nov 07, 2017
by
old-bear
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add authentication doc part in client.md
parent
73fb4865
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletion
+21
-1
client.md
docs/cn/client.md
+21
-1
No files found.
docs/cn/client.md
View file @
633d8a3c
...
...
@@ -605,7 +605,27 @@ baidu_std和hulu_pbrpc协议支持附件,这段数据由用户自定义,不
在http协议中,附件对应
[
message body
](
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
)
,比如要POST的数据就设置在request_attachment()中。
## 认证
TODO: Describe how authentication methods are extended.
client端的认证一般分为2种:
1.
基于请求的认证:每次请求都会带上认证信息。这种方式比较灵活,认证信息中可以含有本次请求中的字段,但是缺点是每次请求都会需要认证,性能上有所损失
2.
基于连接的认证:当TCP连接建立后,client发送认证包,认证成功后,后续该连接上的请求不再需要认证。相比前者,这种方式灵活度不高(一般ren认证包里只能携带本机一些静态信息),但性能较好,一般用于单连接/连接池场景
针对第一种认证场景,在实现上非常简单,将认证的格式定义加到请求结构体中,每次当做正常RPC发送出去即可;针对第二种场景,brpc提供了一种机制,只要用户继承实现:
```
c++
class
Authenticator
{
public
:
virtual
~
Authenticator
()
{}
// Implement this method to generate credential information
// into `auth_str' which will be sent to `VerifyCredential'
// at server side. This method will be called on client side.
// Returns 0 on success, error code otherwise
virtual
int
GenerateCredential
(
std
::
string
*
auth_str
)
const
=
0
;
};
```
那么当用户并发调用RPC接口用单连接往同一个server发请求时,框架会自动保证:建立TCP连接后,连接上的第一个请求中会带有上述
`GenerateCredential`
产生的认证包,其余剩下的并发请求不会带有认证信息,依次排在第一个请求之后。整个发送过程依旧是并发的,并不会等第一个请求先返回。若server端认证成功,那么所有请求都能成功返回;若认证失败,一般server端则会关闭连接,这些请求则会收到相应错误。
## 重置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment