<commit_before>(* Copyright (C) 2015, <NAME>
 * See the README file for details. *)

open Lwt
open V1_LWT

let () = Log.(set_log_level INFO)

(* Never used, but needed to create the store. *)
let task s = Irmin.Task.create ~date:0L ~owner:"Server" s

module Store = Irmin.Basic(Irmin_mem.Make)(Irmin.Contents.String)

module Bundle = Tc.Pair(Store.Private.Slice)(Store.Head)

let show_head = function
  | None -> "(none)"
  | Some head -> String.sub (Irmin.Hash.SHA1.to_hum head) 0 6

module Main (Stack:STACKV4) (Conf:KV_RO) (Clock:V1.CLOCK) = struct
  module TCP  = Stack.TCPV4
  module TLS  = Tls_mirage.Make (TCP)
  module X509 = Tls_mirage.X509 (Conf) (Clock)
  module S = Cohttp_mirage.Server(TLS)

  let respond_static segments =
    let path = String.concat "/" segments in
    match Static.read path with
    | Some body -> S.respond_string ~status:`OK ~body ()
    | None -> S.respond_not_found ()

  (* Split a URI into a list of path segments *)
  let split_path uri =
    let path = Uri.path uri in
    let rec aux = function
      | [] | [""] -> []
      | hd::tl -> hd :: aux tl
    in
    List.filter (fun e -> e <> "")
      (aux (Re_str.(split_delim (regexp_string "/") path)))

  (* Import bundle from client into store. *)
  let accept_push s body =
    let headers = Cohttp.Header.init_with "Content-Type" "application/octet-stream" in
    let s = s "import" in
    Cohttp_lwt_body.to_string body >>= fun body ->
    let buf = Mstruct.of_string (B64.decode body) in
    let (slice, head) = Bundle.read buf in
    Store.head s >>= function
    | Some server_head when server_head = head ->
        S.respond_string ~headers ~status:`OK ~body:"ok" ()
    | server_head -><commit_msg>Set Content-Type header for HTML responses<commit_after>(* Copyright (C) 2015, <NAME>
 * See the README file for details. *)

open Lwt
open V1_LWT

let () = Log.(set_log_level INFO)

(* Never used, but needed to create the store. *)
let task s = Irmin.Task.create ~date:0L ~owner:"Server" s

module Store = Irmin.Basic(Irmin_mem.Make)(Irmin.Contents.String)

module Bundle = Tc.Pair(Store.Private.Slice)(Store.Head)

let show_head = function
  | None -> "(none)"
  | Some head -> String.sub (Irmin.Hash.SHA1.to_hum head) 0 6

module Main (Stack:STACKV4) (Conf:KV_RO) (Clock:V1.CLOCK) = struct
  module TCP  = Stack.TCPV4
  module TLS  = Tls_mirage.Make (TCP)
  module X509 = Tls_mirage.X509 (Conf) (Clock)
  module S = Cohttp_mirage.Server(TLS)

  let respond_static segments =
    let path = String.concat "/" segments in
    match Static.read path with
    | None -> S.respond_not_found ()
    | Some body ->
        let headers =
          if Filename.check_suffix path ".html" then
            Cohttp.Header.init_with "Content-Type" "text/html"
          else
            Cohttp.Header.init () in
        S.respond_string ~headers ~status:`OK ~body ()

  (* Split a URI into a list of path segments *)
  let split_path uri =
    let path = Uri.path uri in
    let rec aux = function
      | [] | [""] -> []
      | hd::tl -> hd :: aux tl
    in
    List.filter (fun e -> e <> "")
      (aux (Re_str.(split_delim (regexp_string "/") path)))

  (* Import bundle from client into store. *)
  let accept_push s body =
    let headers = Cohttp.Header.init_with "Content-Type" "application/octet-stream" in
    let s = s "import" in
    Cohttp_lwt_body.to_string body >>= fun body ->
    let buf = Mstruct.of_string (B64.decode body) in
    let (slice, head) = Bundle.read buf in
    Store.head s >>= function
    | Some server_head when server_head = head ->
        S.respond_string ~headers ~status:`OK ~body:"ok" ()
    | server_head ->
{'fraction_non_alphanumeric': 0.12884615384615383, 'fraction_numerical': 0.01098901098901099, 'mean_word_length': 2.9619151251360174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '2805853', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1237, 'n_words': 369}