File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
src/main/clojure/cljs/repl Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 60
60
(fn [old]
61
61
(update-in old [method] #(conj (vec %) m))))))
62
62
63
+ (defn parse-file-parts [file]
64
+ ; ; This is a port of java.net.URL.Parts, which is package private.
65
+ (let [ref-idx (str/index-of file " #" )
66
+ [file ref] (if ref-idx
67
+ [(subs file 0 ref-idx) (subs file (inc ref-idx))]
68
+ [file nil ])
69
+ q-idx (str/last-index-of file \?)]
70
+ (merge {:ref ref}
71
+ (if q-idx
72
+ {:path (subs file 0 q-idx)
73
+ :query-str (subs file (inc q-idx))}
74
+ {:path file}))))
75
+
63
76
; ;; assumes first line already consumed
64
77
(defn parse-headers
65
78
" Parse the headers of an HTTP POST request."
80
93
(conj header-lines next-line)))))
81
94
82
95
(defn read-post [line rdr]
83
- (let [[_ path _] (str/split line #" " )
96
+ (let [[_ file _] (str/split line #" " )
97
+ {:keys [path ref query-str]} (parse-file-parts file)
84
98
headers (parse-headers (read-headers rdr))
85
99
content-length (Integer/parseInt (:content-length headers))
86
100
content (char-array content-length)]
87
101
(io! (.read rdr content 0 content-length)
88
102
{:method :post
89
103
:path path
104
+ :ref ref
105
+ :query-str query-str
90
106
:headers headers
91
107
:content (String. content)})))
92
108
93
109
(defn read-get [line rdr]
94
- (let [[_ path _] (str/split line #" " )
110
+ (let [[_ file _] (str/split line #" " )
111
+ {:keys [path ref query-str]} (parse-file-parts file)
95
112
headers (parse-headers (read-headers rdr))]
96
113
{:method :get
97
114
:path path
115
+ :ref ref
116
+ :query-str query-str
98
117
:headers headers}))
99
118
100
119
(defn read-request [rdr]
You can’t perform that action at this time.
0 commit comments