You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/06/12 17:02:36 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #3647: Fix for missing port in redirect to https

rawlinp commented on a change in pull request #3647: Fix for missing port in redirect to https
URL: https://github.com/apache/trafficcontrol/pull/3647#discussion_r293018988
 
 

 ##########
 File path: traffic_monitor/srvhttp/srvhttp.go
 ##########
 @@ -186,7 +187,15 @@ func (s *Server) RunHTTPSRedirect(addr string, addrForRedirect string, readTimeo
 }
 
 func (s *Server) redirectTLS(w http.ResponseWriter, r *http.Request) {
-	host, _, _ := net.SplitHostPort(r.Host)
+	host, _, err := net.SplitHostPort(r.Host)
+	if err != nil {
+		if strings.Contains(err.Error(), "missing port in address") {
+			host = r.Host
+		} else {
+			w.WriteHeader(http.StatusInternalServerError)
+			w.Write([]byte(`{"error": "marshalling: ` + err.Error() + `"}`))
 
 Review comment:
   This error context seems a little vague. Instead of `marshalling` would it be more clear to say `getting host from request`?
   
   Also, I'm guessing if err != nil that `host` will just be an empty string. Would that still work with the redirect below? What does `s.addrToRedirect` usually contain, just the port suffix like `":443"`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services