#!/usr/bin/env bash

brt_curl() {
  local url="${1:-}"
  if [[ -z "$url" ]]; then
    brt_error "Usage: brt -curl <url> [curl flags...]"
    exit 1
  fi
  shift
  brt_require curl

  local tmp stats
  tmp=$(mktemp)
  stats=$(mktemp)

  curl -sS -w "http_code:%{http_code}\nsize:%{size_download}\ntime:%{time_total}\n" \
    -o "$tmp" "$@" "$url" > "$stats"

  cat "$tmp"
  echo
  brt_info "Response stats:"
  cat "$stats"
  rm -f "$tmp" "$stats"
}
