安全地进行 http 重定向

标签 go url-redirection

我知道在 PHP 网络应用程序中,如果您使用 header('Location: http://somewhere.com ') 进行重定向,但您没有 die()/exit(),则始终执行并显示 header 函数之后的代码。我想知道在 Go 中使用 http.Redirect(w, r, "/somewhere", 302) 时是否会发生同样的情况。如果是,如何避免。

最佳答案

http.Redirect 函数写入一个完整的响应。程序在调用 http.Redirect 后继续执行。如果对 http.Redirect 的调用不是函数的最后一行,那么应用程序通常会在调用后立即从处理程序返回。

func serveFoo(w http.ResponseWriter, r *http.Request) {
   ...
      http.Redirect(w, r, "/somewhere", 302)
      return
   ...

} 

关于安全地进行 http 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47643065/

相关文章:

Android : Getting a Bitmap from a url connection (graph. facebook.com)重定向到另一个网址

javascript - 从一个 AngularJS 应用程序切换到另一个——页面内容未更新

pointers - Golang 向下类型转换结构

apache - 如何使用 Apache 将 Go 应用程序与 MediaWiki 一起部署?

go - Gin-Gonic 中间件声明

regex - 获取url参数并保存变量或cookie

java - 如何在 java 中跟踪重定向的 url?

即使所有中间件都被注释掉,Laravel 5.3 api 路由也会重定向

c++ - ECDSA签名验证: Go vs OpenSSL

go - 在 golang 中通过 websocket 编写客户端