我正在尝试将github.com/willnorris/imageproxy/集成到现有服务器上,并将图像投放到" / proxy /"路径。我有:
String protocol = Protocol.HTTP.toString();
String host = "somproxy.foo";
int port = 8888;
String path = null;
String auth = null;
String fragment = null;
URI uri = new URI(protocol, auth, host, port, path, null, fragment);
ProxyConfiguration.Builder builder = ProxyConfiguration.builder().endpoint(uri);
ProxyConfiguration proxyConfiguration = builder.build();
ApacheSdkHttpClientFactory
apacheSdkHttpClientFactory =
ApacheSdkHttpClientFactory.builder().proxyConfiguration(proxyConfiguration).build();
this.s3Client = S3Client.builder()
.region(region)
.httpConfiguration(ClientHttpConfiguration.builder()
.httpClientFactory(apacheSdkHttpClientFactory)
.build())
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.build();
SdkAsyncHttpClientFactory sdkAsyncHttpClientFactory = null;
SdkAsyncHttpClient sdkHttpClient = null;
当我尝试调整图像大小时,第一个数字似乎被截止:
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"willnorris.com/go/imageproxy"
)
func main() {
p := imageproxy.NewProxy(nil, nil)
router := mux.NewRouter()
router.NewRoute().Name("proxy").Methods("GET").PathPrefix("/proxy/").Handler(http.StripPrefix("/proxy/", p))
server := &http.Server{
Addr: ":8000",
Handler: router,
}
//server.Handler = p
log.Printf("Listening at %v", server.Addr)
log.Fatal(server.ListenAndServe())
}
返回50x50图像而不是250x250图像。
可以访问250x250的图像
http://127.0.0.1:8000/proxy/250x,/https:/octodex.github.com/images/codercat.jpg
取消注释http://127.0.0.1:8000/proxy/2250x,/https:/octodex.github.com/images/codercat.jpg
作品和图片会按预期调整大小。
答案 0 :(得分:0)
在调用图像代理处理程序之前,使用http.StripPrefix从请求路径中删除“/ proxy”。请注意,StripPrefix的第一个参数没有尾随/。
router.NewRoute().Name("proxy").Methods("GET").PathPrefix("/proxy/").Handler(http.StripPrefix("/proxy", p))