Ok, it works only if I am not using *http.ListenAndServeTLS(...)*, which I
need use... My point is that i want force everybody to use https.
*func redir(w http.ResponseWriter, req *http.Request) {*
* http.Redirect(w, req, "https://147.83.74.89:4000"+req.RequestURI,
http.StatusMovedPermanently)*
*}*
*func main() {*
* authenticator := auth.NewBasicAuthenticator("Train Controler", Secret)
*
* http.HandleFunc("/", authenticator.Wrap(rootHandler))*
* http.Handle("/socket", websocket.Handler(websocketServer))*
* *
*// _ := http.ListenAndServeTLS(listenAddr, "./tls/cert.pem",
"./tls/key.pem", nil)*
* _ := http.ListenAndServe(listenAddr, http.HandlerFunc(redir))*
*}*
El martes, 12 de marzo de 2013 18:31:58 UTC+1, Patrick Mylund Nielsen
escribió:
If you want to keep the path/request params, you can do something like
this:
http://play.golang.org/p/Yslp7rllOv# curl -i localhost:8080/foo?bar=baz
HTTP/1.1 301 Moved Permanently
Date: Tue, 12 Mar 2013 17:29:32 GMT
Location:
https://yourhostname.com/foo?bar=bazTransfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
<a href="https://yourhostname.com/foo?bar=baz">Moved Permanently</a>.
You might want to look into setting a HSTS header as well:
http://en.wikipedia.org/wiki/HTTP_Strict_Transport_SecurityOn Tue, Mar 12, 2013 at 12:19 PM, Ricardo Fernandez <
fernandez...@gmail.com <javascript:>> wrote:
Hi everybody,
There is any way to redirect the http request to https? I want redirect
all
http://127.0.0.1 to
https://127.0.0.1I've been trying with RedirectHandler(url string, code int) how you can
see:
func main() {
authenticator := auth.NewBasicAuthenticator("Train Controler", Secret)
http.HandleFunc("/", authenticator.Wrap(rootHandler))
http.Handle("/socket", websocket.Handler(websocketServer))
err := http.ListenAndServeTLS("127.0.0.1", "./tls/cert.pem",
"./tls/key.pem", nil)
err2 := http.ListenAndServe("127.0.0.1", http.RedirectHandler("
https://127.0.0.1", http.StatusFound))
if err != nil || err2 != nil {
log.Fatal(err)
}
}
Thanks a lot for your help, and sorry if it is too easy I am a golang
newbie.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts...@googlegroups.com <javascript:>.
For more options, visit
https://groups.google.com/groups/opt_out.--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.