MCPcopy
hub / github.com/writefreely/writefreely / LogHandlerFunc

Method LogHandlerFunc

handle.go:932–982  ·  view source on GitHub ↗
(f http.HandlerFunc)

Source from the content-addressed store, hash-verified

930}
931
932func (h *Handler) LogHandlerFunc(f http.HandlerFunc) http.HandlerFunc {
933 return func(w http.ResponseWriter, r *http.Request) {
934 h.handleHTTPError(w, r, func() error {
935 status := 200
936 start := time.Now()
937
938 defer func() {
939 if e := recover(); e != nil {
940 log.Error("Handler.LogHandlerFunc\n\n%s: %s", e, debug.Stack())
941 h.errors.InternalServerError.ExecuteTemplate(w, "base", pageForReq(h.app.App(), r))
942 status = 500
943 }
944
945 // TODO: log actual status code returned
946 log.Info(h.app.ReqLog(r, status, time.Since(start)))
947 }()
948
949 if h.app.App().cfg.App.Private {
950 // This instance is private, so ensure it's being accessed by a valid user
951 // Check if authenticated with an access token
952 _, apiErr := optionalAPIAuth(h.app.App(), r)
953 if apiErr != nil {
954 if err, ok := apiErr.(impart.HTTPError); ok {
955 status = err.Status
956 } else {
957 status = 500
958 }
959
960 if apiErr == ErrNotLoggedIn {
961 // Fall back to web auth since there was no access token given
962 _, err := webAuth(h.app.App(), r)
963 if err != nil {
964 if err, ok := apiErr.(impart.HTTPError); ok {
965 status = err.Status
966 } else {
967 status = 500
968 }
969 return err
970 }
971 } else {
972 return apiErr
973 }
974 }
975 }
976
977 f(w, r)
978
979 return nil
980 }())
981 }
982}
983
984func (h *Handler) Gopher(f gopherFunc) gopher.HandlerFunc {
985 return func(w gopher.ResponseWriter, r *gopher.Request) {

Callers 1

InitRoutesFunction · 0.80

Calls 7

handleHTTPErrorMethod · 0.95
pageForReqFunction · 0.85
optionalAPIAuthFunction · 0.85
webAuthFunction · 0.85
AppMethod · 0.65
ReqLogMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected