From 78917ed5cba003e36c281dcfddc050ac70e5202b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 11 Feb 2020 10:00:10 +0800 Subject: [PATCH] comment updates for package ghttp --- net/ghttp/ghttp_client_response.go | 13 +++++++------ net/ghttp/ghttp_controller.go | 2 +- net/ghttp/ghttp_request_auth.go | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/net/ghttp/ghttp_client_response.go b/net/ghttp/ghttp_client_response.go index c08de241f..84a4dd57c 100644 --- a/net/ghttp/ghttp_client_response.go +++ b/net/ghttp/ghttp_client_response.go @@ -7,18 +7,19 @@ package ghttp import ( + "github.com/gogf/gf/util/gconv" "io/ioutil" "net/http" "time" ) -// 客户端请求结果对象 +// ClientResponse is the struct for client request response. type ClientResponse struct { *http.Response cookies map[string]string } -// 获得返回的指定COOKIE值 +// GetCookie retrieves and returns the cookie value of specified . func (r *ClientResponse) GetCookie(key string) string { if len(r.cookies) == 0 { now := time.Now() @@ -32,7 +33,7 @@ func (r *ClientResponse) GetCookie(key string) string { return r.cookies[key] } -// 获取返回的数据(二进制). +// ReadAll retrieves and returns the response content as []byte. func (r *ClientResponse) ReadAll() []byte { body, err := ioutil.ReadAll(r.Body) if err != nil { @@ -41,12 +42,12 @@ func (r *ClientResponse) ReadAll() []byte { return body } -// 获取返回的数据(字符串). +// ReadAllString retrieves and returns the response content as string. func (r *ClientResponse) ReadAllString() string { - return string(r.ReadAll()) + return gconv.UnsafeBytesToStr(r.ReadAll()) } -// 关闭返回的HTTP链接 +// Close closes the response when it will never be used. func (r *ClientResponse) Close() error { r.Response.Close = true return r.Body.Close() diff --git a/net/ghttp/ghttp_controller.go b/net/ghttp/ghttp_controller.go index 1d2a4337e..376c1427b 100644 --- a/net/ghttp/ghttp_controller.go +++ b/net/ghttp/ghttp_controller.go @@ -6,7 +6,7 @@ package ghttp -// 控制器接口 +// Controller is the base struct for controller. type Controller interface { Init(*Request) Shut() diff --git a/net/ghttp/ghttp_request_auth.go b/net/ghttp/ghttp_request_auth.go index cce9009af..0f35ac65a 100644 --- a/net/ghttp/ghttp_request_auth.go +++ b/net/ghttp/ghttp_request_auth.go @@ -14,7 +14,7 @@ import ( "github.com/gogf/gf/encoding/gbase64" ) -// 设置Basic Auth校验提示 +// setBasicAuth sets the http basic authentication tips. func (r *Request) setBasicAuth(tips ...string) { realm := "" if len(tips) > 0 && tips[0] != "" { @@ -26,8 +26,9 @@ func (r *Request) setBasicAuth(tips ...string) { r.Response.WriteHeader(http.StatusUnauthorized) } -// 设置HTTP基础账号密码认证,如果用户没有提交账号密码,那么提示用户输出信息。 -// 验证成功之后返回true,否则返回false。 +// BasicAuth enables the http basic authentication feature with given passport and password +// and asks client for authentication. It returns true if authentication success, else returns +// false if failure. func (r *Request) BasicAuth(user, pass string, tips ...string) bool { auth := r.Header.Get("Authorization") if auth == "" {