Skip to content

Commit

Permalink
🐛 fix(response.clj): change function signature of url-as-file to matc…
Browse files Browse the repository at this point in the history
…h conventional style

🐛 fix(response.clj): add conditional check to canonical-path to handle directories correctly
  • Loading branch information
ccfontes committed Aug 27, 2023
1 parent 5461afd commit d5f1a21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ my-function:
In `bb` language:
[source, clojure]
----
(defn handler [{:keys [headers body context] :as event}] ...)
(defn handler [{:keys [headers body context] :as event}]
...)
----
The `event` is a map containing the request `:headers`, `:body` and `:context` keys.
`event` is a map containing `:headers`, `:body` and `:context` keys.

`context` contains a map of environment variables.

The `:headers` key contains headers, as such:
`:headers` contains headers, as such:
[source, clojure]
----
{:content-type "application/json"}
----

The `:env` map contains a map with the environment variables. Additional environment variables can be defined in the `stack.yml` file, as such:
`:body` is the payload body.

`:context` contains environment variables. Additional environment variables can be defined in the `stack.yml` file, as such:
[source, yml]
----
my-function:
Expand All @@ -78,14 +79,14 @@ my-function:
MY_ENV1: foo
MY_ENV2: 2
----
The `:env` key will contain:
`:context` will contain:
[source, clojure]
----
{:my-env1 "foo"
:my-env2 2}
----

There are cases where string keys are preferable in the payload body, and it's possible to support them by setting `keywords: false` in the Function in `stack.yml`:
There are cases where it's preferable to have string keys in the payload body, and it's possible to support them by setting `keywords: false` in the Function in `stack.yml`:
[source, yml]
----
my-function:
Expand Down
2 changes: 1 addition & 1 deletion template/bb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ USER app
WORKDIR $HOME

COPY index.clj function/bb.edn ./
COPY ring ./ring
COPY lib ./lib
COPY function function

RUN bb prepare && bb print-deps
Expand Down
4 changes: 2 additions & 2 deletions template/bb/lib/ring/util/response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

(defn- canonical-path ^String [^File file]
(str (.getCanonicalPath file)
(if (.isDirectory file) File/separatorChar)))
(when (.isDirectory file) File/separatorChar)))

(defn- safe-path? [^String root ^String path]
(.startsWith (canonical-path (File. root path))
Expand Down Expand Up @@ -173,7 +173,7 @@
;; As a work-around, we'll backport the fix from CLJ-1177 into
;; url-as-file.

(defn- ^File url-as-file [^java.net.URL u]
(defn- url-as-file ^File [^java.net.URL u]
(-> (.getFile u)
(str/replace \/ File/separatorChar)
(str/replace "+" (URLEncoder/encode "+" "UTF-8"))
Expand Down

0 comments on commit d5f1a21

Please sign in to comment.