Skip to content

Commit 7c981da

Browse files
committed
Add header
1 parent 2d48304 commit 7c981da

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject tadam-core "0.3.1"
1+
(defproject tadam-core "0.3.2"
22
:description "First version"
33
:url "https://github.com/tadam-framework/tadam-core"
44
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"

src/tadam/responses.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
(:require
33
[ring.util.response :as ring-response]))
44

5+
(def headers {"X-Powered-By" "Clojure/Tadam"
6+
"Content-Type" "text/html"})
7+
58
(defn response
69
"Return response"
710
([req body]
811
{:status 200
9-
:headers {"Content-Type" "text/html"}
12+
:headers headers
1013
:body body
1114
:session (-> req :session)})
1215
([req body status]
1316
{:status status
14-
:headers {"Content-Type" "text/html"}
17+
:headers headers
1518
:body body
1619
:session (-> req :session)})
1720
([req body status content-type]
1821
{:status status
19-
:headers {"Content-Type" content-type}
22+
:headers (assoc headers "Content-Type" content-type)
2023
:body body
2124
:session (-> req :session)}))
2225

test/tadam/templates_test.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55

66
(deftest raw-HTML
77
(testing "Raw HTML simple"
8-
(is (= (templates/raw-HTML {:req "test"} "<html><body></body></html>" {}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<html><body></body></html>", :session nil})))
8+
(is (= (templates/raw-HTML {:req "test"} "<html><body></body></html>" {}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body></body></html>", :session nil})))
99
(testing "Raw HTML with param"
10-
(is (= (templates/raw-HTML {:req "test"} "<html><body>{{ hello }}</body></html>" {:hello "world"}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<html><body>world</body></html>", :session nil}))))
10+
(is (= (templates/raw-HTML {:req "test"} "<html><body>{{ hello }}</body></html>" {:hello "world"}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body>world</body></html>", :session nil}))))
1111

1212
(deftest render-HTML
1313
(testing "Simple"
14-
(is (= (templates/render-HTML {:req "test"} (resource "html/simple.html") {}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil})))
14+
(is (= (templates/render-HTML {:req "test"} (resource "html/simple.html") {}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil})))
1515
(testing "With param"
16-
(is (= (templates/render-HTML {:req "test"} (resource "html/with-param.html") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil}))))
16+
(is (= (templates/render-HTML {:req "test"} (resource "html/with-param.html") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil}))))
1717

1818
(deftest render-404
1919
(testing "Simple"
20-
(is (= (templates/render-404 {:req "test"} (resource "html/simple.html") {}) {:status 404, :headers {"Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil})))
20+
(is (= (templates/render-404 {:req "test"} (resource "html/simple.html") {}) {:status 404, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil})))
2121
(testing "With param"
22-
(is (= (templates/render-404 {:req "test"} (resource "html/with-param.html") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 404, :headers {"Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil}))))
22+
(is (= (templates/render-404 {:req "test"} (resource "html/with-param.html") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 404, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<html><body><h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p></body></html>\n", :session nil}))))
2323

2424
(deftest render-markdown
2525
(testing "Simple"
26-
(is (= (templates/render-markdown {:req "test"} (resource "markdown/simple.md") {}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<h1>Title</h1><p>Hello <strong>world</strong></p>", :session nil})))
26+
(is (= (templates/render-markdown {:req "test"} (resource "markdown/simple.md") {}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<h1>Title</h1><p>Hello <strong>world</strong></p>", :session nil})))
2727
(testing "With param"
28-
(is (= (templates/render-markdown {:req "test"} (resource "markdown/with-param.md") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 200, :headers {"Content-Type" "text/html"}, :body "<h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p>", :session nil}))))
28+
(is (= (templates/render-markdown {:req "test"} (resource "markdown/with-param.md") {:rating "Awesome" :url "https://tadam-framework.dev"}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "text/html"}, :body "<h1>Title</h1><p>Tadam is Awesome</p><p><a href='https://tadam-framework.dev'>Website</a></p>", :session nil}))))
2929

3030
(deftest render-json
3131
(testing "Simple"
32-
(is (= (templates/render-JSON {:req "test"} {:name "Tadam" :type "Framework"}) {:status 200, :headers {"Content-Type" "application/json"}, :body "{\"name\":\"Tadam\",\"type\":\"Framework\"}", :session nil}))))
32+
(is (= (templates/render-JSON {:req "test"} {:name "Tadam" :type "Framework"}) {:status 200, :headers {"X-Powered-By" "Clojure/Tadam", "Content-Type" "application/json"}, :body "{\"name\":\"Tadam\",\"type\":\"Framework\"}", :session nil}))))

0 commit comments

Comments
 (0)