net::ERR_CONTENT_LENGTH_MISMATCH

I am having an issue with a GO application that serves an Angular application when navigating to the http server. The browser comes back with a console error stating net::ERR_CONTENT_LENGTH_MISMATCH

The angular application is stored in a folder called dist.

Here is the code for serving the application

//create new gorilla mux router
r := mux.NewRouter()

// Handle all preflight request
r.Methods("OPTIONS").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	// fmt.Printf("OPTIONS")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
	w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Access-Control-Request-Headers, Access-Control-Request-Method, Connection, Host, Origin, User-Agent, Referer, Cache-Control, X-header")
	w.WriteHeader(http.StatusNoContent)
	return
})

dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
	log.Fatal(err)
}

r.Handle("/socket.io/", server)
r.Handle("/login", http.StripPrefix("/login", http.FileServer(http.Dir(dir+"/client/"))))
r.Handle("/dashboard", http.StripPrefix("/dashboard", http.FileServer(http.Dir(dir+"/client/"))))!
r.PathPrefix("/").Handler(http.FileServer(http.Dir(dir + "/client/")))

srv := &http.Server{
	Handler:      r,
	Addr:         "0.0.0.0:2000",
	WriteTimeout: 15 * time.Second,
	ReadTimeout:  15 * time.Second,
}

log.Fatal(srv.ListenAndServe())

Here is the error I am receiving.

It also took a minute for those requests to complete (error out). I would look at the usual suspects on Windows - antivirus, and then possibly a proxy if you use one.

I am able to access it locally with no problem. It appears to happen when trying to access the webserver over a vpn connection. That appears to be the issue? Unless there is another issue with

The requests that error out appear to be random. Sometimes only one will error out (fail) or many will.

I’m afraid it sounds like a problem with your environment somehow, rather than with the Go server side.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.