Redirecting from Filters in Revel

I was working on Login functionality for web app, and wanted to redirect user from Filter using Redirect, but rather then being redirected, I was seeing a blank page. The code looked something like this

func LoginFilter(c *revel.Controller, fc []revel.Filter) {
	// .. do some pre-processing ..
	requestUrl := c.Request.URL.Path
	if c.Session["userEmail"] == "" {
		c.Redirect(controllers.Home.Index)
		return
	}
	var userEmail string
	userEmail = c.Session["userEmail"]
	c.RenderArgs["userEmail"] = userEmail
	fc[0](c, fc[1:]) // Execute the next filter stage.
	// .. do some post-processing ..
}

The idea being if there is userEmail set in session, proceed forward, otherwise redirect to homepage.

It was not working. Not sure why.

I had to change it to

func LoginFilter(c *revel.Controller, fc []revel.Filter) {
	// .. do some pre-processing ..
	requestUrl := c.Request.URL.Path
	if c.Session["userEmail"] == "" {
		c.Response.Out.Header().Set("Location", "/")
		c.Response.WriteHeader(http.StatusFound, "")
	}
	var userEmail string
	userEmail = c.Session["userEmail"]
	c.RenderArgs["userEmail"] = userEmail
	fc[0](c, fc[1:]) // Execute the next filter stage.
	// .. do some post-processing ..
}

That worked for me.

I am still not sure, what is the reason why the redirect was not working. If any of you have any idea, do post in the comments.

Thanks!

~~ Whizdumb ~~
Email : sachin.xpert@gmail.com