|
151 | 151 | :body (grumpy/resource "robots.txt")})])) |
152 | 152 |
|
153 | 153 |
|
154 | | -(defn suppress-error [name class message-re] |
155 | | - (interceptor/interceptor |
156 | | - {:name name |
157 | | - :error |
158 | | - (fn [ctx ^Throwable e] |
159 | | - (let [cause (stacktrace/root-cause e) |
160 | | - message (.getMessage cause)] |
161 | | - (if (and (instance? class cause) (re-matches message-re message)) |
162 | | - (do |
163 | | - (println "Ignoring" (type cause) "-" message) |
164 | | - ctx) |
165 | | - (assoc ctx :io.pedestal.interceptor.chain/error e))))})) |
| 154 | +; Filtering out Broken pipe reporting |
| 155 | +; io.pedestal.http.impl.servlet-interceptor/error-stylobate |
| 156 | +(defn error-stylobate [{:keys [servlet-response] :as context} exception] |
| 157 | + (let [cause (stacktrace/root-cause exception)] |
| 158 | + (if (and (instance? IOException cause) (= "Broken pipe" (.getMessage cause))) |
| 159 | + (println "Ignoring java.io.IOException: Broken pipe") |
| 160 | + (io.pedestal.log/error |
| 161 | + :msg "error-stylobate triggered" |
| 162 | + :exception exception |
| 163 | + :context context)) |
| 164 | + (@#'io.pedestal.http.impl.servlet-interceptor/leave-stylobate context))) |
| 165 | + |
| 166 | + |
| 167 | +; io.pedestal.http.impl.servlet-interceptor/stylobate |
| 168 | +(def stylobate |
| 169 | + (io.pedestal.interceptor/interceptor {:name ::stylobate |
| 170 | + :enter @#'io.pedestal.http.impl.servlet-interceptor/enter-stylobate |
| 171 | + :leave @#'io.pedestal.http.impl.servlet-interceptor/leave-stylobate |
| 172 | + :error error-stylobate})) |
166 | 173 |
|
167 | 174 |
|
168 | 175 | (defrecord Server [opts crux server] |
169 | 176 | component/Lifecycle |
170 | 177 | (start [this] |
171 | 178 | (println "[server] Starting web server at" (str (:host opts) ":" (:port opts))) |
172 | | - (let [server (-> {::http/routes (routes/sort (concat routes auth/routes authors/routes)) |
173 | | - ::http/router :linear-search |
174 | | - ::http/type :immutant |
175 | | - ::http/host (:host opts) |
176 | | - ::http/port (:port opts) |
177 | | - ::http/secure-headers {:content-security-policy-settings "object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"}} |
178 | | - (http/default-interceptors) |
179 | | - (update ::http/interceptors conj no-cache) |
180 | | - (update ::http/interceptors #(cons (suppress-error ::suppress-broken-pipe java.io.IOException #"Broken pipe") %)) |
181 | | - (http/create-server) |
182 | | - (http/start))] |
183 | | - (assoc this :server server))) |
| 179 | + (with-redefs [io.pedestal.http.impl.servlet-interceptor/stylobate stylobate] |
| 180 | + (let [server (-> {::http/routes (routes/sort (concat routes auth/routes authors/routes)) |
| 181 | + ::http/router :linear-search |
| 182 | + ::http/type :immutant |
| 183 | + ::http/host (:host opts) |
| 184 | + ::http/port (:port opts) |
| 185 | + ::http/secure-headers {:content-security-policy-settings "object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"}} |
| 186 | + (http/default-interceptors) |
| 187 | + (update ::http/interceptors conj no-cache) |
| 188 | + (http/create-server) |
| 189 | + (http/start))] |
| 190 | + (assoc this :server server)))) |
184 | 191 | (stop [this] |
185 | 192 | (println "[server] Stopping web server") |
186 | 193 | (http/stop server) |
|
0 commit comments