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

Content-type dispatch via multimethod #742

Merged
merged 7 commits into from
Jan 5, 2022
Merged

Conversation

plexus
Copy link
Contributor

@plexus plexus commented Jan 1, 2022

Duplicate of #548 to see if CircleCI is happier this way.

  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing
  • The new code is not generating reflection warnings
  • You've updated the README (if adding/changing middleware)

Note: If you're just starting out to hack on cider-nrepl you might find
nREPL's documentation and the
"Design" section of the README extremely useful.*

Thanks!

plexus added 2 commits January 1, 2022 15:44
Make the content-type middleware that handles inlining of File/URL/Image
extensible through a multimethod. This makes it possible for developers to add
handling of custom types.

Regular Clojure values can be given a `:type` metadata to make them
distinguishable. Other types can dispatch on the class.
Further document the content-type middleware.
@plexus plexus force-pushed the arne/content-type-dispatch branch from 6cffcd9 to 9d598c2 Compare January 1, 2022 21:17
@plexus
Copy link
Contributor Author

plexus commented Jan 1, 2022

Hey, look at that @bbatsov !

@plexus
Copy link
Contributor Author

plexus commented Jan 1, 2022

Working on adding a test, then I think this is done.

@plexus
Copy link
Contributor Author

plexus commented Jan 2, 2022

This is good to go from my end! Happy that in the end all it took was three years of patience :D

@bbatsov
Copy link
Member

bbatsov commented Jan 2, 2022

@plexus Looks great! Just one small thing - you can't edit ops.adoc directly as it's auto-generated from the middleware descriptors (there's a lein docs task for this).

(select-keys [:body :content-type :content-transfer-encoding :status]))))))

(testing "java.awt.image.RenderedImage"
(is (= {:body (if (SystemUtils/IS_JAVA_1_8)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I'd favor a simple (re-find #"^1.8." (System/getProperty "java.version")) to depending on a third party

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I merely looked around to see how it was done elsewhere in the codebase. If this is overkill we can remove it here and in info-test in a separate PR.

Apply the changes to the ops documentation in the middleware descriptor, then
regenerate the docs from there. Fix the location of the `:returns` map so it
shows up in the docs, and change `content-type-middleware` to `content-type` to
be in line with the others (none of them use a `-middleware` suffix in the
descriptor).
@plexus
Copy link
Contributor Author

plexus commented Jan 4, 2022

Got it @bbatsov , I've made the doc changes in the middleware descriptors and ran lein docs.

We expect a string in the response, and this allows us to take a shorter path
for several types, and to bypass coerction to java.net.URL.
Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

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

Thanks for the iteration!

@bbatsov bbatsov merged commit 389cc1b into master Jan 5, 2022
@bbatsov bbatsov deleted the arne/content-type-dispatch branch January 5, 2022 04:51
@bbatsov
Copy link
Member

bbatsov commented Jan 5, 2022

🥳 🚀

@plexus
Copy link
Contributor Author

plexus commented Jan 5, 2022

Yay! @arrdem must be happy we're finally out of his mentions :P

@arrdem
Copy link
Contributor

arrdem commented Jan 5, 2022

Old friends always welcome 😉

@bbatsov
Copy link
Member

bbatsov commented Jan 5, 2022

@arrdem I thought we were all young friends. 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants