-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrap-validation middleware to validate Ring requests
Add new aleph.http.schema ns
- Loading branch information
Showing
3 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns aleph.http.schema | ||
(:require [malli.core :as m] | ||
[malli.util :as mu])) | ||
|
||
(def server-port [:maybe :int]) | ||
(def server-name [:maybe :string]) | ||
(def remote-addr [:maybe :string]) | ||
(def uri [:maybe :string]) | ||
(def query-string [:maybe :string]) | ||
(def scheme [:enum :http :https]) | ||
(def request-method :keyword) | ||
(def content-type [:maybe [:or :string :keyword]]) | ||
(def content-length [:maybe :int]) | ||
(def character-encoding [:maybe :string]) | ||
|
||
(def ring-request [:map | ||
[:request-method request-method] | ||
[:server-port {:optional true} server-port] | ||
[:server-name {:optional true} server-name] | ||
[:remote-addr {:optional true} remote-addr] | ||
[:uri {:optional true} uri] | ||
[:query-string {:optional true} query-string] | ||
[:scheme {:optional true} scheme] | ||
[:content-type {:optional true} content-type] | ||
[:content-length {:optional true} content-length] | ||
[:character-encoding {:optional true} character-encoding]]) | ||
|
||
(def validate-request (m/validator ring-request)) | ||
(def explain-request (m/explainer ring-request)) | ||
|
||
|
||
|
||
|
||
|
||
(comment | ||
|
||
(map #(m/validate server-port %) ["bingo" nil 123]) | ||
|
||
(m/validate ring-request | ||
{:server-port 80 | ||
:server-name "www.example.com" | ||
:remote-addr "127.0.0.1" | ||
:uri "/blah/blah" | ||
:query-string "?foo=bar" | ||
:scheme :https | ||
:request-method :get}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters