首页 文章

安全地进行http重定向

提问于
浏览
0

我知道在PHP Web应用程序中,如果使用 Headers 重定向('Location:http://somewhere.com ') but you don't die()/ exit(),则会始终执行并显示 Headers 函数之后的代码 . 我想知道何时使用http . Go中的重定向(w,r,"/somewhere",302)发生了相同的情况 . 如果是,怎么可以避免它 .

1 回答

  • 2

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

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

相关问题