func (le *LetsEncrypt) StartHTTPServer() *http.Server {
	// Setup simple web-server that listens to tokens and returns back.. things
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		token := strings.TrimPrefix(r.URL.String(), "/.well-known/acme-challenge/")
		response, err := le.AcmeClient.HTTP01ChallengeResponse(token)
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte(response))
	})

	server := &http.Server{Addr: ":" + le.HTTPPort}
	go func() {
		err := server.ListenAndServe()
		if err != nil && err != http.ErrServerClosed {
			fmt.Printf("We cannot start a HTTP server on port %s on your machine.\n", le.HTTPPort)
			if err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EADDRINUSE {
				fmt.Printf("It seems there is already a server running on port %s.\n", le.HTTPPort)
			} else if err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EACCES {
				fmt.Printf("It seems you are not running as root/Administrator, which is needed to use port %s.\n", le.HTTPPort)
			} else {
				fmt.Printf("An unknown error has occurred: %s\n", err)
			}
			os.Exit(1)
		}
	}()

	return server
}
// StartHTTPServer will start the HTTP server in the background which is called by LetsEncrypt for validating orders.
StartHTTPServer will start the HTTP server in the background which is called by LetsEncrypt for validating orders.
// StartHTTPServer will start the HTTP server in the background which is called by LetsEncrypt for validating orders .
func (le *LetsEncrypt) StartHTTPServer() *http.Server {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		token := strings.TrimPrefix(r.URL.String(), "/.well-known/acme-challenge/")
		response, err := le.AcmeClient.HTTP01ChallengeResponse(token)
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte(response))
	})
	server := &http.Server{Addr: ":" + le.HTTPPort}
	go func() {
		err := server.ListenAndServe()
		if err != nil && err != http.ErrServerClosed {
			fmt.Printf("We cannot start a HTTP server on port %s on your machine.\n", le.HTTPPort)
			if err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EADDRINUSE {
				fmt.Printf("It seems there is already a server running on port %s.\n", le.HTTPPort)
			} else if err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EACCES {
				fmt.Printf("It seems you are not running as root/Administrator, which is needed to use port %s.\n", le.HTTPPort)
			} else {
				fmt.Printf("An unknown error has occurred: %s\n", err)
			}
			os.Exit(1)
		}
	}()
	return server
}
func ( le * LetsEncrypt ) StartHTTPServer ( ) * http . Server { http . HandleFunc ( " " , func ( w http . ResponseWriter , r * http . Request ) { token := strings . TrimPrefix ( r . URL . String ( ) , " " ) response , err := le . AcmeClient . HTTP01ChallengeResponse ( token ) if err != nil { w . WriteHeader ( http . StatusNotFound ) return } w . WriteHeader ( http . StatusOK ) _ , _ = w . Write ( [ ] byte ( response ) ) } ) server := & http . Server { Addr : " " + le . HTTPPort } go func ( ) { err := server . ListenAndServe ( ) if err != nil && err != http . ErrServerClosed { fmt . Printf ( " \n " , le . HTTPPort ) if err . ( * net . OpError ) . Err . ( * os . SyscallError ) . Err == syscall . EADDRINUSE { fmt . Printf ( " \n " , le . HTTPPort ) } else if err . ( * net . OpError ) . Err . ( * os . SyscallError ) . Err == syscall . EACCES { fmt . Printf ( " \n " , le . HTTPPort ) } else { fmt . Printf ( " \n " , err ) } os . Exit ( 1 ) } } ( ) return server }
StartHTTPServer will start the HTTP server in the background which is called by LetsEncrypt for validating orders.
StartHTTPServer will start the HTTP server in the background which is called by LetsEncrypt for validating orders .
// Setup simple web-server that listens to tokens and returns back.. things