Skip to content

Repository files navigation

firehttp

一个专门用于开发安全工具的HTTP类库.

特点

  1. header、params、body 均支持string和map定义, 太方便了.
  2. 可以获取到HTTP请求/响应的原始HTTP报文.
  3. 使用起来,真心简单.
  4. 尽量用优雅的编程方式,让go代码读起来不那么丑陋.
  5. 自己摸索吧.

Example

发送一个普通的GET请求

package main
import (
"fmt""github.com/dean2021/firehttp""log"
)
funcmain() {
f:=firehttp.New(nil)
resp, err:=f.Get("http://www.jd.com", nil)
iferr!=nil {
log.Fatal(err)
}
fmt.Println(resp.String())
}

发送一个复杂的GET请求

package main
import (
"github.com/dean2021/firehttp""time""log""fmt"
)
funcmain() {
f:=firehttp.New(&firehttp.HTTPOptions{
// HTTP代理地址,推荐用burpsuite进行调试Proxy: "http://127.0.0.1:8080",
// DNS缓存有效时间DNSCacheExpire: time.Minute*5,
// 空闲链接MaxIdleConn: 1,
// HTTP握手超时设置TLSHandshakeTimeout: time.Second*5,
// 拨号建立连接完成超时时间DialTimeout: time.Second*5,
// KeepAlive 超时时间DialKeepAlive: time.Second*5,
})
resp, err:=f.Get("https://www.jd.com/index.php", &firehttp.ReqOptions{
// GET参数,支持map[string]string 和 stringParams: "id=1",
// header参数,支持map[string]string 和 stringHeader: "Cookie: xxxx\r\n",
// 请求总超时时间Timeout: time.Second*10,
// 表示这个请求是一个ajax请求,自动追加Content-TypeIsAjax: true,
// 禁止跳转DisableRedirect: true,
// 使用cookie会话UseCookieJar:true,
// 跳过https证书验证InsecureSkipVerify:true,
// 禁止gzip请求压缩DisableCompression: true,
})
iferr!=nil {
log.Fatal(err)
}
// 输出HTTP请求报文fmt.Println(resp.RawHTTPRequest())
// 输出HTTP响应报文fmt.Println(resp.RawHTTPResponse())
// 输出响应状态码fmt.Println(resp.StatusCode())
// 输出响应内容fmt.Println(resp.String())
}

发送一个POST请求

package main
import (
"fmt""github.com/dean2021/firehttp""log"
)
funcmain() {
f:=firehttp.New(nil)
resp, err:=f.Post("https://www.jd.com", &firehttp.ReqOptions{
Body: "xxxx",
})
iferr!=nil {
log.Fatal(err)
}
fmt.Println(resp.RawHTTPRequest())
}

上传一个文件

package main
import (
"fmt""github.com/dean2021/firehttp""log"
)
funcmain() {
f:=firehttp.New(nil)
resp, err:=f.Post("http://www.baidu.com/upload.php", &firehttp.ReqOptions{
Files: []firehttp.FileUpload{
{
FieldName: "passwd",
FileName: "/etc/passwd",
},
},
})
iferr!=nil {
log.Fatal(err)
}
fmt.Println(resp.StatusCode())
}

代码简单易懂,建议有空通读一遍代码,相信会有新的发现。

使用文档

HTTP OPTION 设置参数

// HTTP Request 参数typeHTTPOptionsstruct {
// 代理地址Proxystring// DNS缓存有效时间DNSCacheExpire time.Duration// 空闲连接数MaxIdleConnint// TLS握手超时时间TLSHandshakeTimeout time.Duration// 拨号建立连接完成超时时间DialTimeout time.Duration// KeepAlive 超时时间DialKeepAlive time.Duration
}

Request Option 设置参数

// HTTP Request 参数typeReqOptionsstruct {
// 请求get参数Paramsinterface{}
// 设置请求headerHeaderinterface{}
// 整个请求(包括拨号/请求/重定向)等待的最长时间。Timeout time.Duration// 上传文件Files []FileUpload// 禁用跳转DisableRedirectbool// 请求bodyBodyinterface{}
// 基础认证账号密码BasicAuthUserAndPass []string// 设置ajax headerIsAjaxbool// 设置JSON headerIsJSONbool// 设置XML headerIsXMLbool// 自定义http clientHTTPClient*http.Client// 使用cookie会话UseCookieJarboolCookieJar http.CookieJar// 跳过证书验证InsecureSkipVerifybool// 禁用请求gzip压缩DisableCompressionbool
}

文档待完善...

thanks

大量参考这个两个类库的代码, 特此感谢 levigross 和 Gay4 同学.

  1. grequests / https://github.com/levigross/grequests
  2. zhttp / https://github.com/Greyh4t/zhttp

About

一个专门用于开发安全工具的HTTP类库.

Topics

Resources

Stars

22 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages