File tree 1 file changed +9
-0
lines changed 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package routes
6
6
7
7
import (
8
8
"bytes"
9
+ stdcontext "context"
9
10
"encoding/gob"
10
11
"net/http"
11
12
"os"
@@ -90,6 +91,13 @@ func setupAccessLogger(m *macaron.Macaron) {
90
91
})
91
92
}
92
93
94
+ func requestTimeout (ctx * macaron.Context ) {
95
+ // TODO make timeout configurable
96
+ httpContext := ctx .Req .Context ()
97
+ newContext , _ := stdcontext .WithTimeout (httpContext , time .Second * 5 )
98
+ ctx .Req .WithContext (newContext )
99
+ }
100
+
93
101
// RouterHandler is a macaron handler that will log the routing to the default gitea log
94
102
func RouterHandler (level log.Level ) func (ctx * macaron.Context ) {
95
103
return func (ctx * macaron.Context ) {
@@ -127,6 +135,7 @@ func NewMacaron() *macaron.Macaron {
127
135
if setting .EnableAccessLog {
128
136
setupAccessLogger (m )
129
137
}
138
+ m .Use (requestTimeout )
130
139
m .Use (macaron .Recovery ())
131
140
if setting .EnableGzip {
132
141
m .Use (gzip .Middleware ())
You can’t perform that action at this time.
0 commit comments