dryl34156 2017-12-11 03:56
浏览 47
已采纳

无法在图像代理上调整图像大小

I am trying to integrate github.com/willnorris/imageproxy/ on an existing server and have the images served on "/proxy/" path. I have:

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())
}

When I try to resize an image, the first digit seems to get cutoff: http://127.0.0.1:8000/proxy/250x,/https:/octodex.github.com/images/codercat.jpg

returns a 50x50 image rather than a 250x250 image.

A 250x250 image is accessable by http://127.0.0.1:8000/proxy/2250x,/https:/octodex.github.com/images/codercat.jpg

Uncommenting server.Handler = p works and images are resized as expected.

  • 写回答

1条回答 默认 最新

  • douwen8424 2017-12-11 05:33
    关注

    Use http.StripPrefix to remove "/proxy" from the request path before invoking the image proxy handler. Note that there's not a trailing / on the first argument to StripPrefix.

    router.NewRoute().Name("proxy").Methods("GET").PathPrefix("/proxy/").Handler(http.StripPrefix("/proxy", p))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题