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

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

golang http disable TRACE method

问题

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

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

go func() {
    logger.Log(
        "level", 1,
        "action", "start https",
        "addr", opts.httpsAddr,
    )

    s := &http.Server{
        Addr:    opts.httpsAddr,
        Handler: server,
        TLSConfig: &tls.Config{
            MinVersion: tls.VersionTLS12,
        },
    }
    http2.ConfigureServer(s, nil)

    fatal("failed to start HTTPS: %s", s.ListenAndServeTLS(opts.tlsCrt, opts.tlsKey))
}()

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

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

go func() {
		logger.Log(
			&quot;level&quot;, 1,
			&quot;action&quot;, &quot;start https&quot;,
			&quot;addr&quot;, opts.httpsAddr,
		)

		s := &amp;http.Server{
			Addr:    opts.httpsAddr,
			Handler: server,
			TLSConfig: &amp;tls.Config{
				MinVersion: tls.VersionTLS12,
			},
		}
		http2.ConfigureServer(s, nil)

		fatal(&quot;failed to start HTTPS: %s&quot;, s.ListenAndServeTLS(opts.tlsCrt, opts.tlsKey))
	}()

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

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:

确定