Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update schema to accept string HTTP methods like "GET", as well as keywords. #685

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Unreleased

* Loosen `wrap-validation` validation to support strings in :request-method. (See release in 0.6.2 for more information).

### 0.7.1

* Bump Manifold to 0.4.2 to fix Promesa print-method hierarchy bug
Expand Down Expand Up @@ -34,11 +38,14 @@ Contributions by Matthew Davidson and Stefan van den Oord.

* Fix backwards-compatibility for transport options
* Bump Netty to 4.1.89.Final, and io_uring to 0.0.18.Final
* Add `wrap-validation` middleware to validate Ring maps
* Bump deps and example deps
* Upgrade CircleCI instance size
* Switch to pedantic deps for CircleCI

### Breaking changes

* Add `wrap-validation` middleware to validate Ring maps [#679](https://github.com/clj-commons/aleph/pull/679). This adds a stricter interpretation of the ring spec, which may fail on previously valid input. For example, strings (e.g. `"GET"`) and keywords (e.g. `:get`) were both accepted values for `:request-method`, but now only keywords are accepted. This will be fixed in the release after 0.7.1.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the bit about "a stricter interpretation of the Ring spec". The ring spec never allowed strings, we just accepted them by accident.


Contributions by Arnaud Geiser, Ertuğrul Çetin, Jeroen van Dijk, David Ongaro,
Matthew Davidson, and Moritz Heidkamp.

Expand Down
2 changes: 1 addition & 1 deletion src/aleph/http/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(def uri [:maybe :string])
(def query-string [:maybe :string])
(def scheme [:enum :http :https])
(def request-method :keyword)
(def request-method [:or :string :keyword])
(def content-type [:maybe [:or :string :keyword]])
(def content-length [:maybe :int])
(def character-encoding [:maybe :string])
Expand Down
6 changes: 6 additions & 0 deletions test/aleph/http/client_middleware_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
(doseq [req (mg/sample schema/ring-request)]
(is (middleware/wrap-validation req)))

(testing "Request methods can be strings"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modulo the testing import that is missing. :)

(is (middleware/wrap-validation {:remote-addr "localhost"
:server-name "computer"
:scheme :http
:request-method "GET"})))

(is (thrown-with-msg?
IllegalArgumentException
#"Invalid spec.*:in \[:request-method\].*:type :malli.core/missing-key"
Expand Down