Very tiny caching HTTP proxy

blov · · 509 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi,</p> <p>at work we tried to configure the Apache HTTP server to act as a reverse proxy with caching. We couldn&#39;t get it to work in more than three hours. At home I wrote exactly this in two hours: A reverse proxy that caches the requests: <a href="https://github.com/hauke96/tiny-http-proxy" rel="nofollow">https://github.com/hauke96/tiny-http-proxy</a></p> <p>It would be great if I get some feedback to the code: What could go wrong using it? What could be done more efficient/readable/elegant/shorter/...?</p> <p>Regards Hauke</p> <hr/>**评论:**<br/><br/>tsdtsdtsd: <pre><p>I believe you should use a custom <a href="https://golang.org/pkg/net/http/#Client" rel="nofollow">http.Client</a> instead of a direct http.Get, so you can set a meaningful timeout. And maybe you want to handle redirects in a custom way too. <a href="https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779" rel="nofollow">This</a> is a nice article about that stuff. EDIT: also check the comments in that article, some good stuff there too.</p></pre>tv64738: <pre><p>He should definitely plumb up the incoming context to the outgoing one, to get request cancellation.</p></pre>theo_retiker: <pre><p>Thanks for this article, I thought all the time that there&#39;s a default timeout like 30 seconds. But now I&#39;m using the http.Client and http.Server (as mentioned in the comments, the default server has timeout issues too).</p></pre>-amir: <pre><p>Seems like the cache is not thread safe...</p></pre>theo_retiker: <pre><p>Oh, yes, that&#39;s right and something I&#39;ll work on later. Thank for the hint :)</p></pre>dahlma: <pre><p>This is cool! I&#39;ve written a proxy as well, unfortunately not something I can share but so far it&#39;s worked out pretty well. I&#39;m storing the data in a DB instead of file system since I&#39;m running the app on heroku, I need it to not rely on the filesystem (s3 may be an option but would need to look into latency)</p> <p>I&#39;m wondering though, when you save the information to the filesystem, does that retain headers?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

509 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传