Skip to content

Commit

Permalink
Add support for GraalVM ResourceURLConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryCod committed Sep 15, 2021
1 parent cfc0be3 commit bc87e3b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ring-core/src/ring/util/response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@
(if-not (zero? last-mod)
(Date. last-mod))))

(defmethod resource-data :resource
[^java.net.URL url]
;; GraalVM creates a resource substitution for regular resources on SubstrateVM
;; @see https://github.com/oracle/graal/blob/db22885e2deb21ff0c1a72314f7b9bb86b7d334c/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceURLConnection.java#L38
;;
;; Differences between regular URLConnection & ResourceURLConnection:
;; - `resource:` - protocol instead of `jar:` or `file:`
;; - no way of checking if the resource is a directory
(let [resource (.openConnection url)]
{:content (.getInputStream resource)
:content-length (connection-content-length resource)
:last-modified (connection-last-modified resource)}))

(defmethod resource-data :jar
[^java.net.URL url]
(let [conn (.openConnection url)]
Expand Down

0 comments on commit bc87e3b

Please sign in to comment.