Exemplo n.º 1
0
// TODO sort mirrorlist?
func printMirrorList(w http.ResponseWriter, r *http.Request, requestFile mirrorbrain.RequestFile) {
	path := requestFile.Path()
	servers, err := database.FindServers(path)
	if err != nil {
		http.Error(w, "internal error", http.StatusInternalServerError)
		return
	}
	mirrorbrain.CreateServerLists(requestFile, ExtractIP(r.RemoteAddr), servers)
	fileInfo, err = database.SelectFileInfo(path)
}
Exemplo n.º 2
0
func sendRedirect(w http.ResponseWriter, r *http.Request, requestFile mirrorbrain.RequestFile) {

	path := requestFile.Path()
	servers, err := database.FindServers(path)
	if err != nil {
		http.Error(w, "internal error", http.StatusInternalServerError)
		return
	}
	dumpServers(servers)
	serverSelection := mirrorbrain.ChooseServer(requestFile, ExtractIP(r.RemoteAddr), servers)
	if serverSelection.FoundIn != "" {
		log.Println("Using server:", serverSelection)
		http.Redirect(w, r, serverSelection.Chosen.RedirectUrl(path), http.StatusFound)
	} else {
		log.Println("No usable mirrors after classification for:", requestFile.Path())
		http.NotFound(w, r)
	}
}