In `renderStatic`, `modTime` should be set to the file's mod time if it exists. If the file does not exist, `renderStatic` should
- keep `modTime` uninitialized,
- return early with a `404 Not Found` error.
Fixes #60.
mrngm
was assigned by electricdusk2020-05-30 17:55:28 +02:00
Instead of adding a debug parameter here, would it make sense to set router.Use(rl.recoveryMiddleware) inside TestIssue60?
funcTestIssue60(t*testing.T){srv,rl:=createTemporaryRouter(t)srv.Use(rl.recoveryMiddleware)srv.Use(rl.metricsMiddleware)// Request a nonexistent static filereq,err:=http.NewRequest("GET","/css/nonexistent_file.css",nil)iferr!=nil{t.Fatal(err)}rr:=httptest.NewRecorder()srv.ServeHTTP(rr,req)checkStatusCode(t,rr,http.StatusNotFound)
And, if we want debugging options, this should be a globally configurable option, instead of a function parameter.
Instead of adding a debug parameter here, would it make sense to set `router.Use(rl.recoveryMiddleware)` inside `TestIssue60`?
```go
func TestIssue60(t *testing.T) {
srv, rl := createTemporaryRouter(t)
srv.Use(rl.recoveryMiddleware)
srv.Use(rl.metricsMiddleware)
// Request a nonexistent static file
req, err := http.NewRequest("GET", "/css/nonexistent_file.css", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
srv.ServeHTTP(rr, req)
checkStatusCode(t, rr, http.StatusNotFound)
```
And, if we want debugging options, this should be a globally configurable option, instead of a function parameter.
So you mean, as a global variable? So in this case, debug describes that the panic recovery middleware should be disabled, because otherwise we cannot run the tests. We could also change the name debug to noPanicMiddleware.
What kind of solution would be good here?
So you mean, as a global variable? So in this case, `debug` describes that the panic recovery middleware should be disabled, because otherwise we cannot run the tests. We could also change the name `debug` to `noPanicMiddleware`.
What kind of solution would be good here?
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
In
renderStatic,modTimeshould be set to the file's mod time if it exists. If the file does not exist,renderStaticshouldmodTimeuninitialized,404 Not Founderror.Fixes #60.
@@ -58,3 +58,3 @@rootURL: rootURL,}return CreateMainRouter(&rl), &rlreturn CreateMainRouter(&rl, true), &rl(see comment below on the use of
debugas a function parameter)@@ -40,6 +41,7 @@ func (rl *rushlink) recoveryMiddleware(next http.Handler) http.Handler {}()if err := recover(); err != nil {w.WriteHeader(500)Can we definitively state that
panic()s are caused due to errors on the server side?Yes.
panics during runtime should always indicate a bug.@@ -81,3 +83,3 @@// CreateMainRouter creates the main Gorilla router for the application.func CreateMainRouter(rl *rushlink) *mux.Router {func CreateMainRouter(rl *rushlink, debug bool) *mux.Router {Instead of adding a debug parameter here, would it make sense to set
router.Use(rl.recoveryMiddleware)insideTestIssue60?And, if we want debugging options, this should be a globally configurable option, instead of a function parameter.
So you mean, as a global variable? So in this case,
debugdescribes that the panic recovery middleware should be disabled, because otherwise we cannot run the tests. We could also change the namedebugtonoPanicMiddleware.What kind of solution would be good here?
@@ -120,3 +124,3 @@srv := &http.Server{Handler: CreateMainRouter(&rl),Handler: CreateMainRouter(&rl, false),(see comment above on the use of
debugas a function parameter)