-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to point the specific ip and port for client? #10
Comments
@toranger Sorry, but I don't understand your problem, could you explain it to me? P.S. If you mean how to hack the COS backend address which is resolved via dns, you can hack it via setup |
To use the port and ip instead of using the bucket host |
@toranger You can do it via setup For example, one way is via change host of request url: // demo.go
package main
import (
"context"
"net/http"
"github.com/mozillazg/go-cos"
)
type DemoTransport struct {
RemoteAddr string
Transport http.RoundTripper
}
func (t *DemoTransport) RoundTrip(req *http.Request) (*http.Response, error) {
host := req.Host
if host == "" {
host = req.URL.Host
}
req.URL.Host = t.RemoteAddr
req.Host = host
resp, err := t.transport().RoundTrip(req)
return resp, err
}
func (t *DemoTransport) transport() http.RoundTripper {
if t.Transport != nil {
return t.Transport
}
return http.DefaultTransport
}
func main() {
b, _ := cos.NewBaseURL("http://test-1253846586.cos.ap-beijing-1.myqcloud.com")
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: "test",
SecretKey: "test",
Transport: &DemoTransport{
RemoteAddr: "127.0.0.1:8080",
},
},
})
c.Bucket.Get(context.Background(), nil)
} Start a demo server on another window:
Test:
Local demo server will receive the request:
Another way is via hack dns resolver or connection creator: |
Or just use b, _ := cos.NewBaseURL("http://127.0.0.1:8080")
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: "test",
SecretKey: "test",
},
}) |
No description provided.
The text was updated successfully, but these errors were encountered: