File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
src/main/clojure/cljs/repl Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 37
37
" .cljc" " text/x-clojure"
38
38
" .map" " application/json" })
39
39
40
+ (def mime-type->encoding
41
+ {" text/html" " UTF-8"
42
+ " text/css" " UTF-8"
43
+ " image/jpeg" " ISO-8859-1"
44
+ " image/png" " ISO-8859-1"
45
+ " image/gif" " ISO-8859-1"
46
+ " text/javascript" " UTF-8"
47
+ " text/x-clojure" " UTF-8"
48
+ " application/json" " UTF-8" })
49
+
40
50
(defn- set-return-value-fn
41
51
" Save the return value function which will be called when the next
42
52
return value is received."
96
106
:else nil )
97
107
local-path)]
98
108
(if local-path
99
- (server/send-and-close conn 200 (slurp local-path)
100
- (if (some #(.endsWith path %) (keys ext->mime-type))
101
- (get ext->mime-type path)
102
- " text/plain" ))
109
+ (if-let [ext (some #(if (.endsWith path %) %) (keys ext->mime-type))]
110
+ (let [mime-type (ext->mime-type ext " text/plain" )
111
+ encoding (mime-type->encoding mime-type " UTF-8" )]
112
+ (server/send-and-close
113
+ conn
114
+ 200
115
+ (slurp local-path :encoding encoding)
116
+ mime-type
117
+ encoding))
118
+ (server/send-and-close conn 200 (slurp local-path) " text/plain" ))
103
119
(server/send-404 conn path)))
104
120
(server/send-404 conn path)))
105
121
Original file line number Diff line number Diff line change 108
108
([conn status form]
109
109
(send-and-close conn status form " text/html" ))
110
110
([conn status form content-type]
111
- (let [utf-8-form (.getBytes form " UTF-8" )
112
- content-length (count utf-8-form)
111
+ (send-and-close conn status form content-type " UTF-8" ))
112
+ ([conn status form content-type encoding]
113
+ (let [byte-form (.getBytes form encoding)
114
+ content-length (count byte-form)
113
115
headers (map #(.getBytes (str % " \r\n " ))
114
116
[(status-line status)
115
117
" Server: ClojureScript REPL"
116
118
(str " Content-Type: "
117
119
content-type
118
- " ; charset=utf-8 " )
120
+ " ; charset=" encoding )
119
121
(str " Content-Length: " content-length)
120
122
" " ])]
121
123
(with-open [os (.getOutputStream conn)]
122
124
(doseq [header headers]
123
125
(.write os header 0 (count header)))
124
- (.write os utf-8 -form 0 content-length)
126
+ (.write os byte -form 0 content-length)
125
127
(.flush os)
126
128
(.close conn)))))
127
129
You can’t perform that action at this time.
0 commit comments