在Golang的net/http中设置服务器软件变量。

huangapple go评论77阅读模式
英文:

setting server software variable in Golang net/http

问题

我正在使用ab -c 100 -n 10000 http://{你的IP地址}:8000/对我的应用程序进行基准测试,一切都很好,但是由于我是一个有强迫症的人,我发现在描述服务器时,返回的结果中有以下内容:

服务器软件:
服务器主机名:localhost
服务器端口:1337

文档路径:/
文档长度:19字节

我该如何设置服务器软件变量?我不能接受那个空字段存在的情况。

英文:

I'm benchmarking my application with ab -c 100 -n 10000 http://{your ip}:8000/, everything is fine, but being obsessive as I am, I found that while describing the server, it came back with

Server Software:        
Server Hostname:        localhost
Server Port:            1337

Document Path:          /
Document Length:        19 bytes

How do I set the Server Software variable? I can't live with that empty field right there.

答案1

得分: 1

设置一个Server头。参见RFC-2616第14.38节ResponseWriter.Header。

w.Header().Set("Server", "MyServer")

英文:

Set a Server header. See RFC-2616 section 14.38 and ResponseWriter.Header.

w.Header().Set("Server", "MyServer")

huangapple
  • 本文由 发表于 2014年8月29日 08:23:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/25559931.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定