禁用Golang中的TRACE方法的HTTP请求。

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

golang http disable TRACE method

问题

在golang的net/http包中,是否有类似于Apache中的traceEnable参数?

我有以下类似的代码,但我希望监听GETPOSTHEAD方法,而不监听TRACE方法。

  1. go func() {
  2. logger.Log(
  3. "level", 1,
  4. "action", "start https",
  5. "addr", opts.httpsAddr,
  6. )
  7. s := &http.Server{
  8. Addr: opts.httpsAddr,
  9. Handler: server,
  10. TLSConfig: &tls.Config{
  11. MinVersion: tls.VersionTLS12,
  12. },
  13. }
  14. http2.ConfigureServer(s, nil)
  15. fatal("failed to start HTTPS: %s", s.ListenAndServeTLS(opts.tlsCrt, opts.tlsKey))
  16. }()

基本上,我想在收到这样的请求时返回405状态码。

  1. curl -v -X TRACE https://<server>
英文:

Is there something like the traceEnable parameter in apache, in golang net/http?

I do have something like the following, but I do want to listen to GET, POST and HEAD, however not to the TRACE method

  1. go func() {
  2. logger.Log(
  3. &quot;level&quot;, 1,
  4. &quot;action&quot;, &quot;start https&quot;,
  5. &quot;addr&quot;, opts.httpsAddr,
  6. )
  7. s := &amp;http.Server{
  8. Addr: opts.httpsAddr,
  9. Handler: server,
  10. TLSConfig: &amp;tls.Config{
  11. MinVersion: tls.VersionTLS12,
  12. },
  13. }
  14. http2.ConfigureServer(s, nil)
  15. fatal(&quot;failed to start HTTPS: %s&quot;, s.ListenAndServeTLS(opts.tlsCrt, opts.tlsKey))
  16. }()

Basically I'd like to return a 405 on such a request

  1. curl -v -X TRACE https://&lt;server&gt;

答案1

得分: 1

在golang的net/http包中,没有类似于apache中的traceEnable参数。

你需要在你的处理程序(handler)或中间件(middleware)中自行实现这个功能。

英文:

> Is there something like the traceEnable parameter in apache, in golang net/http?

No.

You have to do that in your handler or middleware.

huangapple
  • 本文由 发表于 2022年7月27日 22:09:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/73139498.html
匿名

发表评论

匿名网友

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

确定