Comments (5)
Add Proxy() function
Fake code
g := gout.New(nil)
s := ""
err := g.GET("http://www.google.com").SetProxy("http://127.0.0.1").BindBody(&s).Do()
if err != nil {
}
Can such an API be?
from gout.
It there an API for changing request origin ? For example proxy https://www.elgoog.com/search?q=test is equivalent to https://www.google.com/search?q=test.
g.Proxy(request, g.ProxyOptopn{
Url: func (url: http.Url) {
// modify the url from elgoog to google
},
Header: map[string]string{origin: 'www.google.com'} // merge and override the origianl request's headers
})
proxy keeps the original methods and other headers unchanged.
from gout.
There are only two APIs for implementing the proxy function in golang. From the documentation point of view, the proxy client is transparent, and only forwards the original request to the proxy server. It seems that the client does not need to do additional processing.
func ProxyFromEnvironment(req *Request) (*url.URL, error)
func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error)
doc
https://golang.google.cn/pkg/net/http/#ProxyURL
from gout.
The proxy function is developed. If there is no problem, I plan to merge it into the main branch.
Below is the test code I wrote.
- proxy-server
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/guonaihong/gout"
)
func main() {
r := gin.Default()
r.Any("/*action", func(c *gin.Context) {
fmt.Printf("%#v\n", c.Request)
var s string
fmt.Printf("url = %s\n", c.Request.URL.String())
err := gout.Def().GET(c.Request.URL.String()).BindBody(&s).Do()
if err != nil {
c.String(200, err.Error())
return
}
c.String(200, s)
})
r.Run(":7000")
}
- proxy-client.go
package main
import (
"fmt"
"github.com/guonaihong/gout"
"log"
)
func main() {
var s string
err := gout.Def().GET("www.qq.com").SetProxy("http://127.0.0.1:7000").BindBody(&s).Do()
if err != nil {
log.Println(err)
return
}
fmt.Println(s)
}
from gout.
I am closed, if you have any questions, you can reopen it.
from gout.
Related Issues (20)
- 怎么上传文件流? HOT 3
- 识别response中的content-encoding HOT 3
- get cookies is array from editThisCookie HOT 7
- 在bind 前,缺少对http status 的判断 比如404 HOT 1
- 有并发问题, 一次bind 会消耗掉多个decoder HOT 4
- 扩展GET/POST/DELETE/PATCH等接口,支持模板语法
- 有没有办法替换掉语言自带的json库? HOT 4
- SetWWWForm会带两个换行符导致请求失败 HOT 2
- SetHeader接口会自动把key字段变成第一个字母大写,其他字母小写. HOT 5
- 优化下文档,补充下结构体tag说明
- 用自定义的http.Client 连接池不起作用 HOT 2
- 高并发下遇到的问题 HOT 9
- Query的数据顺序会乱序 HOT 1
- Query的数据顺序会乱序 HOT 8
- 并发测试如何记录返回结果 HOT 4
- 请教个问题,关于setProxy或者socks的 HOT 9
- 优化反爬 HOT 2
- debug.trace的信息可以提取出来吗? HOT 3
- 有考虑过支持修改ja3指纹嘛 HOT 4
- 如果只获取Response(), 当WithContext在SetTimeout前面时,会导致context cancel错误 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gout.