portkey

Portkey: from REPL to Serverless in one call
baptiste-from-paris 2018-04-02T16:37:02.000539Z

For information @cgrand, this fn work with aws examples

baptiste-from-paris 2018-04-02T16:37:12.000372Z

(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-paris 2018-04-02T16:38:36.000008Z

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

baptiste-from-paris 2018-04-02T16:38:47.000382Z

now I am going to try to make tests pass 😄

viesti 2018-04-02T18:16:34.000210Z

👍 for tests