Comments (4)
@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 AuthorizationTransport.Transport
with your version of http.RoundTripper
(e.g. a modified copy of http.DefaultTransport
) .
ref: https://golang.org/pkg/net/http/#RoundTripper
from go-cos.
@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
AuthorizationTransport.Transport
with your version ofhttp.RoundTripper
(e.g. a modified copy ofhttp.DefaultTransport
) .
To use the port and ip instead of using the bucket host
from go-cos.
@toranger You can do it via setup AuthorizationTransport.Transport
with your version of http.RoundTripper
.
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:
$ echo -e 'HTTP/1.1 200 OK\r\n' | nc -l 8080
Test:
$ go run demo.go
Local demo server will receive the request:
$ echo -e 'HTTP/1.1 200 OK\r\n' | nc -l 8080
GET / HTTP/1.1
Host: test-1253846586.cos.ap-beijing-1.myqcloud.com
User-Agent: go-cos/0.11.0
Authorization: q-sign-algorithm=sha1&q-ak=test&q-sign-time=1546436220;1546439820&q-key-time=1546436220;1546439820&q-header-list=&q-url-param-list=&q-signature=749f551057b64672c6123c80be6babc699bd8030
Content-Type: application/xml
Accept-Encoding: gzip
Another way is via hack dns resolver or connection creator:
from go-cos.
Or just use <ip>:<port>
instead of bucket host as host of bucket url ? go-cos not checking the format of bucket url in case of user may use it in private cloud.
b, _ := cos.NewBaseURL("http://127.0.0.1:8080")
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: "test",
SecretKey: "test",
},
})
from go-cos.
Related Issues (9)
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 go-cos.