golang: multiple http.writeHeader calls
func DownloadFile(w http.ResponseWriter, r *http.Request, sequence uint64, userid string) {
userkey := userid
filename := r.FormValue("filename")
if len(userkey) <= || len(filename) <= {
//........
}
fp := fmt.Sprintf("%s%s/%s", g_sc.Rootdir, userkey, filename)
fd, err := os.Open(fp)
if err == nil {
defer fd.Close()
buf, err := ioutil.ReadAll(fd)
if err != nil {
//.........
} else {
size := len(buf)
w.Header().Add("Content-Length", fmt.Sprintf("%d", size))
fmt.Fprint(w, string(buf))
}
}
}
问题出现在这几行代码:
size := len(buf)
w.Header().Add("Content-Length", fmt.Sprintf("%d", size))
fmt.Fprint(w, string(buf))
buf := new(bytes.Buffer)
buf.Write(...) if err {
// you can use http.Error here, no response has been written yet
http.Error(w, err.String, http.StatusInternalServerError)
return
} if err := buf.WriteTo(w); err != nil {
log.Printf("WriteTo: %v", err)
// you can not use http.Error here anymore. So just log the message (e.g. "broken pipe...")
}
或者注释这两行代码
//w.Header().Add("Content-Length", fmt.Sprintf("%d", size))
fmt.Fprint(w, string(buf))
golang: multiple http.writeHeader calls的更多相关文章
- eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“
你的位置:首页 > Java编程 > eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“ eclipse发布项目报错:Multipl ...
- 链接错误:multiple definition of 'xxx' 问题解决及其原理
内容借鉴 于CSDN炸鸡叔 错因 截图: “multiple definition of 'head' ” “multiple definition of 'tail' ” 解决过程: 1.首先要 ...
- maven pom文件报错:Multiple annotations found at this line 解决方案(转)
研究maven多模块项目时,因为家里和公司不能同时开发,所以把家里搭建好的项目复制到公司继续研究, 当时家里的电脑搭建好项目之后是没问题的,但是复制到公司的eclipse上之后就看到pom文件出现下面 ...
- Xcode10适配——Error:Multiple commands produce
今天苹果正式推送了iOS12,今天上午就更新了最新的iOS,及Xcode10.这次更新还行,不需要我们对以前的项目紧急修复,大动手术. 用Xcode10跑之前的项目,也就报了一种类型的错误:Multi ...
- wordpress插件:multiple post thumbnails(可为文章添加多个特色图片)
我们经常会给wordpress的文章加上特色图片来实现日志缩略图的需求,但是很多时候一张图片并不能够完美而又全面的表达我们wordpress文章的内容,这时候您可能就会需要这样一个能让wordpres ...
- 智汀家庭云-开发指南Golang:设备插件开发
设备插件模块 开发前先阅读插件设计概要:智汀家庭云-开发指南Golang: 插件模块 使用 plugin-sdk 可以忽略不重要的逻辑,快速实现插件 插件实现 获取sdk go get github. ...
- golang:协程安全
多路复用 Go语言中提供了一个关键字select,通过select可以监听channel上的数据流动.select的用法与switch语法类似,由select开始一个新的选择块,每个选择条件由case ...
- Eclipse启动tomcat时报错:Multiple Contexts have a path of "/xxx"
今天使用Eclipse启动tomcat部署项目时,遇到一个奇怪的错误: Could not publish server configuration for Tomcat v6.0 Server at ...
- 论文笔记之:Multiple Feature Fusion via Weighted Entropy for Visual Tracking
Multiple Feature Fusion via Weighted Entropy for Visual Tracking ICCV 2015 本文主要考虑的是一个多特征融合的问题.如何有效的进 ...
随机推荐
- Servlet请求转发RequestDispatcher接口
在Servlet中,利用RequestDispatcher对象,可以将请求转发给另外一个Servlet或JSP页面,甚至是HTML页面,来处理对请求的响应. 一,RequestDispatcher接口 ...
- python学习笔记(7)--爬虫隐藏代理
说明: 1. 好像是这个网站的代理http://www.xicidaili.com/ 2. 第2,3行的模块不用导入,之前的忘删了.. 3. http://www.whatismyip.com.tw/ ...
- Android App性能測试
一.内存 1.查看单个应用App最大内存限制 Command:adb shell "getprop|grep heapgrowthlimit" C:\Users\hujiachun ...
- 介绍编译的less的几种IDE工具
介绍编译的less的两种IDE工具 现在css预编译越来越普及了,著名的有less.sass.stylus等等等等.功能上基本上都是大同小异.这些个玩意儿主要表达的意思就是:“像编程一样的编写你的cs ...
- 在windows中将Tomcat作为服务启动
http://www.cnblogs.com/chuyuhuashi/archive/2012/04/28/2475315.html ————————————————————————————————— ...
- httpoxy 漏洞预警及修复方案
影响范围 PHP.Go.Python等开启CGI(Client)模式的脚本语言 Language 环境依赖 HTTP Client PHP php-fpmmod_php Guzzle 4+Artax ...
- PyQt的QString 和 QStringList
在Qt的C++实现中的QString 和 QStringList 在Python的实现中等效替换为 "str1" 和 ["str1","str2&qu ...
- Worktile中百万级实时消息推送服务的实现
Worktile中百万级实时消息推送服务的实现 出自:http://blog.jobbole.com/81125/
- js数字格式化(加千分位逗号)
需求:当金额大于10000时,在作展示的时候,需要加千分位逗号,就是每隔1000要用逗号分隔: 方法一:使用toLocaleString()方法 此方法和toString()方法的区别看这里 < ...
- win7下cmake编译opencv2.3.1生成opencv—createsamples.exe和opencv_haartrainingd.exe
第一步:下载安装cmake,之后进行默认安装即可,这步略过. 第二步:配置cmake ,使cmake找到opencv进行编译安装 watermark/2/text/aHR0cDovL2Jsb2cuY3 ...