-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #452 from victorgama/CORS
Add CORS header to public resources (Fix #242)
- Loading branch information
Showing
9 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns clojars.http-utils | ||
(:require [ring.middleware | ||
[session :refer [wrap-session]]])) | ||
|
||
(defn wrap-cors-headers [handler] | ||
(fn [req] | ||
(let [response (handler req)] | ||
(if (= 200 (:status response)) | ||
(update-in response [:headers] assoc "Access-Control-Allow-Origin" "*") | ||
response | ||
)))) | ||
|
||
(defn wrap-x-frame-options [f] | ||
(fn [req] (update-in (f req) [:headers] assoc "X-Frame-Options" "DENY"))) | ||
|
||
(defn https-request? [req] | ||
(or (= (:scheme req) :https) | ||
(= (get-in req [:headers "x-forwarded-proto"]) "https"))) | ||
|
||
(defn wrap-secure-session [f] | ||
(let [secure-session (wrap-session f {:cookie-attrs {:secure true | ||
:http-only true}}) | ||
regular-session (wrap-session f {:cookie-attrs {:http-only true}})] | ||
(fn [req] | ||
(if (https-request? req) | ||
(secure-session req) | ||
(regular-session req))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns clojars.test.integration.artifact | ||
(:require [clojure.test :refer :all] | ||
[clojars.test.test-helper :as help] | ||
[clojure.string :as str] | ||
[clj-http.lite.client :as client] | ||
[kerodon.core :refer [session]] | ||
[clojars.test.integration.steps :refer [register-as inject-artifacts-into-repo!]] | ||
[cheshire.core :as json])) | ||
|
||
(use-fixtures :each | ||
help/using-test-config | ||
help/default-fixture | ||
help/with-clean-database | ||
help/run-test-app) | ||
|
||
(defn get-artifact [parts & [opts]] | ||
(-> (str "http://localhost:" help/test-port "/" | ||
(str/join "/" (map name parts))) | ||
(client/get opts))) | ||
|
||
(deftest artifacts-test | ||
(testing "latest-version.json should have permissive cors headers" | ||
(is (help/assert-cors-header (get-artifact ["test" "latest-version.json"]))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters