# lab06 curl 옵션 패턴 모음

# ─── 기본 ────────────────────────────────────────────────────
curl -I  URL                                # 헤더만 (HEAD)
curl -i  URL                                # 헤더 + 바디
curl -v  URL                                # 상세 (DNS/TCP/TLS/인증서)
curl -L  URL                                # 리다이렉트 추적
curl -IL URL                                # 위 두 조합 (가장 자주)
curl -s  URL                                # silent (진행률 숨김)
curl -k  URL                                # 자가서명 인증서 무시 (운영 금지)
curl --connect-timeout 5 --max-time 10 URL  # 타임아웃

# ─── 메서드 + 데이터 ─────────────────────────────────────────
curl -X POST URL -d 'a=1&b=2'                                  # form
curl -X POST URL -H "Content-Type: application/json" -d '{...}' # JSON
curl -X PUT  URL -d 'value=10'
curl -X DELETE URL
curl --data-urlencode "q=hello world" URL                      # URL encode

# ─── 헤더 ────────────────────────────────────────────────────
curl -H "Authorization: Bearer TOKEN" URL
curl -H "X-Forwarded-For: 1.2.3.4" URL
curl -A "Mozilla/5.0" URL                   # User-Agent
curl -e "https://referer.com" URL           # Referer
curl -b "session=abc123" URL                # Cookie 보내기
curl -c cookies.txt URL                     # 응답 쿠키 저장
curl -b cookies.txt URL                     # 저장된 쿠키 사용

# ─── 저장 ────────────────────────────────────────────────────
curl -o page.html URL                       # 지정 파일명
curl -O https://x.com/file.tar.gz           # 원본 파일명
curl -OJ https://x.com/download.cgi         # Content-Disposition

# ─── 시간 측정 (-w) ──────────────────────────────────────────
curl -o /dev/null -s -w \
"DNS=%{time_namelookup}s Connect=%{time_connect}s TLS=%{time_appconnect}s TTFB=%{time_starttransfer}s Total=%{time_total}s\n" URL

# ─── 인증서 ──────────────────────────────────────────────────
curl -vI URL 2>&1 | grep -E "expire|subject:"
openssl s_client -connect HOST:443 -showcerts < /dev/null 2>&1 | grep -E "(subject=|issuer=|Verify)"
curl --cacert /path/ca.pem URL              # 내부 CA
curl --cert client.pem --key client.key URL # 클라이언트 인증서 (mTLS)

# ─── HTTP/2 / HTTP/3 ─────────────────────────────────────────
curl --http2 URL
curl --http3 URL                            # curl 7.66+ + nghttp3

# ─── 운영 자주 ───────────────────────────────────────────────
curl -ILs URL | grep -E "^(HTTP|Location)"  # 리다이렉트 체인 한 줄씩
curl -s URL | jq '.data[]'                  # JSON 파싱
while sleep 5; do curl -s -o /dev/null -w "%{http_code} %{time_total}\n" URL; done  # 헬스체크 루프
