Fork me on GitHub
#portkey
<
2018-04-02
>
baptiste-from-paris16:04:02

For information @cgrand, this fn work with aws examples

baptiste-from-paris16:04:12

(defn req-text->req-map-revisited [req]
  (let [[_ request-method full-uri protocol headers+body] (re-find #"(?s)([A-Z]+)\s(.+)\s(HTTP/1\.1)\n(.*)" req)
        headers (for [[_ header value] (re-seq #"(?s)(\S+):(.*?\n(?:[\t ].*?\n)*)" (str headers+body "\n"))]
                  [header (s/trim-newline value)])
        body (re-find #"Param1=value1" headers+body)
        [_ uri query-string] (re-find #"(?s)([\S&&[^?]]+)\??(\S+)?" full-uri)]
    (cond->
        {:request-method request-method
         :uri full-uri
         :protocol protocol}
      (not (or (empty? headers) (nil? headers))) (assoc :headers
                                                        (into {}
                                                              (x/by-key (comp (interpose ",")
                                                                              x/str))
                                                              headers))
      (not (nil? body)) (assoc :body body)
      (not (nil? query-string)) (assoc :query-string query-string :uri uri)
      true (as->
               req-map
               (assoc req-map :server-name (get-in req-map [:headers "Host"]))
             (update req-map :headers dissoc "Host")))))

baptiste-from-paris16:04:36

I am not the best at regex but at least it does format the way sigv4 needs request

baptiste-from-paris16:04:47

now I am going to try to make tests pass 😄

viesti18:04:34

👍 for tests