|
7 | 7 | [clojure.tools.logging :as log]
|
8 | 8 | [clojure.string :as str]
|
9 | 9 | [manifold.deferred :as d]
|
10 |
| - [manifold.stream :as s]) |
| 10 | + [manifold.stream :as s]) |
11 | 11 | (:import
|
12 | 12 | [java.util
|
13 | 13 | EnumSet
|
|
30 | 30 | ChannelHandlerContext
|
31 | 31 | ChannelHandler
|
32 | 32 | ChannelPipeline]
|
33 |
| - [io.netty.channel.embedded EmbeddedChannel] |
34 | 33 | [io.netty.handler.stream ChunkedWriteHandler]
|
35 | 34 | [io.netty.handler.timeout
|
36 | 35 | IdleState
|
37 | 36 | IdleStateEvent]
|
| 37 | + [io.netty.handler.codec |
| 38 | + TooLongFrameException] |
38 | 39 | [io.netty.handler.codec.http
|
39 | 40 | DefaultFullHttpResponse
|
40 | 41 | HttpContent HttpHeaders HttpUtil
|
|
52 | 53 | TextWebSocketFrame
|
53 | 54 | BinaryWebSocketFrame
|
54 | 55 | CloseWebSocketFrame
|
55 |
| - WebSocketFrame |
56 | 56 | WebSocketFrameAggregator]
|
57 | 57 | [io.netty.handler.codec.http.websocketx.extensions.compression
|
58 | 58 | WebSocketServerCompressionHandler]
|
|
215 | 215 | (defn invalid-request? [^HttpRequest req]
|
216 | 216 | (-> req .decoderResult .isFailure))
|
217 | 217 |
|
218 |
| -(defn reject-invalid-request [ctx ^HttpRequest req] |
219 |
| - (d/chain |
220 |
| - (netty/write-and-flush ctx |
221 |
| - (DefaultFullHttpResponse. |
222 |
| - HttpVersion/HTTP_1_1 |
| 218 | +(defn- ^HttpResponseStatus cause->status [^Throwable cause] |
| 219 | + (if (instance? TooLongFrameException cause) |
| 220 | + (let [message (.getMessage cause)] |
| 221 | + (cond |
| 222 | + (.startsWith message "An HTTP line is larger than") |
223 | 223 | HttpResponseStatus/REQUEST_URI_TOO_LONG
|
224 |
| - (-> req .decoderResult .cause .getMessage netty/to-byte-buf))) |
225 |
| - netty/wrap-future |
226 |
| - (fn [_] (netty/close ctx)))) |
| 224 | + |
| 225 | + (.startsWith message "HTTP header is larger than") |
| 226 | + HttpResponseStatus/REQUEST_HEADER_FIELDS_TOO_LARGE |
| 227 | + |
| 228 | + :else |
| 229 | + HttpResponseStatus/BAD_REQUEST)) |
| 230 | + HttpResponseStatus/BAD_REQUEST)) |
| 231 | + |
| 232 | +(defn reject-invalid-request [ctx ^HttpRequest req] |
| 233 | + (let [cause (-> req .decoderResult .cause) |
| 234 | + status (cause->status cause)] |
| 235 | + (d/chain |
| 236 | + (netty/write-and-flush ctx |
| 237 | + (DefaultFullHttpResponse. |
| 238 | + HttpVersion/HTTP_1_1 |
| 239 | + status |
| 240 | + (-> cause .getMessage netty/to-byte-buf))) |
| 241 | + netty/wrap-future |
| 242 | + (fn [_] (netty/close ctx))))) |
227 | 243 |
|
228 | 244 | (defn ring-handler
|
229 | 245 | [ssl? handler rejected-handler executor buffer-capacity]
|
|
0 commit comments