<commit_before>(ns icecap.handlers.http
  (:require [schema.core :as s]
            [aleph.http :refer [request]]
            [clojure.core.async :refer [to-chan]]
            [icecap.handlers.core :refer [defstep]]
            [manifold.stream :refer [connect]]
            [schema-contrib.core :as sc]
            [taoensso.timbre :refer [info spy]])
  (:import [java.net URI]))


(defn scheme
  "Get the scheme of a (string) URL."
  [^String s]
  (.getScheme (URI. s)))

(defn valid-scheme?
  "Checks if the (string) URL has a valid scheme."
  [^String s]
  (#{"http" "https"} (scheme s)))

(defstep :http
  {:url (s/conditional valid-scheme? sc/URI)
   :method (s/enum :GET :POST :DELETE :PUT :PATCH :HEAD)}
  [step]
  (let [req (spy (request step))]
    (to-chan [(spy @req)])))<commit_msg>Make the tests pass<commit_after>(ns icecap.handlers.http
  (:require [schema.core :as s]
            [aleph.http :refer [request]]
            [clojure.core.async :refer [to-chan]]
            [icecap.handlers.core :refer [defstep]]
            [manifold.stream :refer [connect]]
            [schema-contrib.core :as sc]
            [taoensso.timbre :refer [info spy]])
  (:import [java.net URI]))


(defn valid-url?
  [^String s]
  (try
    (URI. s) true

    (catch Exception _
      false)))

(defn scheme
  "Get the scheme of a (string) URL."
  [^String s]
  (.getScheme (URI. s)))

(defn valid-scheme?
  "Checks if the (string) URL has a valid scheme."
  [^String s]
  (#{"http" "https"} (scheme s)))

(defstep :http
  {:url (s/conditional
         valid-url? (s/conditional
                     valid-scheme? sc/URI
                     'valid-scheme?)
         'valid-url?)
   :method (s/enum :GET :POST :DELETE :PUT :PATCH :HEAD)}
  [step]
  (let [req (spy (request step))]
    (to-chan [(spy @req)])))
{'fraction_non_alphanumeric': 0.16555924695459578, 'fraction_numerical': 0.0, 'mean_word_length': 2.435361216730038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '333869', 'n_tokens_mistral': 651, 'n_tokens_neox': 635, 'n_words': 181}