Documentation ¶
Index ¶
- Constants
- Variables
- func DownloadHTTPFile(url string, saveTo string, timeoutMSec int) (int64, error)
- func GetHTTPFile(url string, timeoutMSec int) ([]byte, error)
- func ParseHTTPRequestLine(line string) (method string, uri string, version string, err error)
- func ParseHTTPStatusLine(line string) (version string, statusCode string, reason string, err error)
- func PostJson(url string, info interface{}, client *http.Client) (*http.Response, error)
- func ReadHTTPHeader(r LineReader) (firstLine string, headers map[string]string, err error)
- func UnmarshalRequestJsonBody(r *http.Request, info interface{}, keyFieldList ...string) error
- type HTTPMsgCtx
- type HTTPReader
- type HTTPReqMsgCtx
- type HTTPRespMsgCtx
- type LineReader
Constants ¶
View Source
const ( HeaderFieldContentLength = "Content-Length" HeaderFieldContentType = "application/json" )
Variables ¶
View Source
var ( ErrHTTPHeader = errors.New("nazahttp: fxxk") ErrParamMissing = errors.New("nazahttp: param missing") )
Functions ¶
func DownloadHTTPFile ¶ added in v0.13.0
获取http文件保存至本地
func GetHTTPFile ¶ added in v0.13.0
获取http文件保存至字节切片
func ParseHTTPRequestLine ¶ added in v0.13.0
Request-Line = Method SP URI SP Version CRLF
func ParseHTTPStatusLine ¶ added in v0.13.0
Status-Line = Version SP Status-Code SP Reason CRLF
func PostJson ¶ added in v0.15.3
@param url 地址 @param info 需要序列化的结构体 @param client 注意,如果为nil,则使用http.DefaultClient
func ReadHTTPHeader ¶ added in v0.13.0
func ReadHTTPHeader(r LineReader) (firstLine string, headers map[string]string, err error)
@return firstLine: request的request line或response的status line @return headers: request header fileds的键值对
Types ¶
type HTTPMsgCtx ¶ added in v0.16.0
type HTTPMsgCtx struct { ReqMethodOrRespVersion string ReqURIOrRespStatusCode string ReqVersionOrRespReason string Headers map[string]string Body []byte }
func ReadHTTPMessage ¶ added in v0.16.0
func ReadHTTPMessage(r HTTPReader) (ctx HTTPMsgCtx, err error)
注意,如果HTTP Header中不包含`Content-Length`,则不会读取HTTP Body,并且err返回值为nil
type HTTPReader ¶ added in v0.16.0
type HTTPReader interface { LineReader io.Reader }
e.g. bufio.Reader
type HTTPReqMsgCtx ¶ added in v0.16.0
type HTTPReqMsgCtx struct { Method string URI string Version string Headers map[string]string Body []byte }
func ReadHTTPRequestMessage ¶ added in v0.16.0
func ReadHTTPRequestMessage(r HTTPReader) (ctx HTTPReqMsgCtx, err error)
type HTTPRespMsgCtx ¶ added in v0.16.0
type HTTPRespMsgCtx struct { Version string StatusCode string Reason string Headers map[string]string Body []byte }
func ReadHTTPResponseMessage ¶ added in v0.16.0
func ReadHTTPResponseMessage(r HTTPReader) (ctx HTTPRespMsgCtx, err error)
type LineReader ¶ added in v0.13.0
Click to show internal directories.
Click to hide internal directories.