mirror of
https://gitee.com/johng/gf
synced 2026-07-02 19:31:07 +08:00
comment updates for package ghttp
This commit is contained in:
@ -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 <key>.
|
||||
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()
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
package ghttp
|
||||
|
||||
// 控制器接口
|
||||
// Controller is the base struct for controller.
|
||||
type Controller interface {
|
||||
Init(*Request)
|
||||
Shut()
|
||||
|
||||
@ -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 == "" {
|
||||
|
||||
Reference in New Issue
Block a user