-
Notifications
You must be signed in to change notification settings - Fork 11
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
New interceptors and updates to existing ones #254
Conversation
- The allowed origin is configurable from env variables and in state it looks for `:cors-url` under `:deps` key - It also supports `preflight` requests
1. JWT has to skip check if request is preflight, so requests with `:options` method is skipped 2. Additional check presence of authorization token in the headers, as it was throwing exceptions due to usage of `str/split`
- Tiny but subtle improvement of params interceptor - Mock and Peridot library used for testing purposes as it allows us to simply mock multipart requests, and many others, but that's what we needed at the moment.
1. The first change I propose here is avoiding nesting coercion result under param type (path, query, form) and just keeping it under params 2. Validation error returns humanized details
If the back-end is Clojure and Front-end Javascript we encounter inconsistency of keys in the context of the language. Hence the experimental solution that we can discuss: 1. kebab-camel interceptor transforms each key upon request to kebab: - original request `{:request {:params {:paramKey1 1 :paramKey2 2 :paramKey3 3}}}` - request after interceptor `{:request {:params {:param-key-1 1 :param-key-2 2 :param-key-3 3}}}` 2. The keys in the response body are also transformed from kebab to camel: - response before interceptor - `{:response {:body {:param-key-1 1 :param-key-2 2 :param-key-3 3}}}` - after `{:response {:body {:paramKey1 1 :paramKey2 2 :paramKey3 3}}}` P.S. `slf4j-simple` is also added to deps to finally get rid of warning at the beginning of http server.
PR included wrapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really need discussion? Seems like a useful thing to have around, and adding it won't alter anything unless the user chooses to use it.
If it really does need discussion then it should be a separate PR
(This is re: camel kebab commit)
Should probably be 4 PRs, (This is only a comment, not a request for change) |
src/xiana/interceptor.clj
Outdated
schemas (or (get-in state [:request-data :match :data method :parameters]) | ||
(get-in state [:request-data :match :data :parameters])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep the merge as it was, to be able to define the path related parameters once, and method parameters separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
src/xiana/interceptor.clj
Outdated
(:path schemas) (valid? (:path schemas) path) | ||
(:query schemas) (valid? (:query schemas) query) | ||
(:form schemas) (valid? (:form schemas) form-params))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How the :query and :form parameters are processed if you defined :path parameters TOO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, the change undone.
agreed. |
8271f7b
to
5f1b83a
Compare
New interceptors and updates to existing ones
CORS headers interceptor
:cors-url
under:deps
keypreflight
requestsError response
Error interceptor wrapped in
bad request
response instead of 200Multipart/form-data support
Coercion improvements
kebab-camel request/request - experimental feature, up for discussion
If the back-end is Clojure and Front-end Javascript we encounter inconsistency of keys in the context of the language.
Hence the experimental solution that we can discuss:
{:request {:params {:paramKey1 1 :paramKey2 2 :paramKey3 3}}}
{:request {:params {:param-key-1 1 :param-key-2 2 :param-key-3 3}}}
{:response {:body {:param-key-1 1 :param-key-2 2 :param-key-3 3}}}
{:response {:body {:paramKey1 1 :paramKey2 2 :paramKey3 3}}}
P.S.
slf4j-simple
is also added todeps.edn
to finally get rid of warning at the beginning of http server.Tester info
All tests are provided
Completion Checklist