mirror of
https://github.com/jaygooby/ttfb.sh
synced 2025-12-10 07:57:21 +01:00
Add a curl passthrough option -o
This lets us send custom switches to curl like -k to ignore invalid certificates. Call ttfb like this: ttfb -o "-k" https://self-signed.badssl.com
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "-l logs to specific file" {
|
@test "-l logs to specific file" {
|
||||||
|
# skip
|
||||||
rundir="$(mktemp -d)"
|
rundir="$(mktemp -d)"
|
||||||
logdir="$(mktemp -d)"
|
logdir="$(mktemp -d)"
|
||||||
pwd="$PWD"
|
pwd="$PWD"
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "-l exits if the path the custom log file doesn't exist" {
|
@test "-l exits if the path the custom log file doesn't exist" {
|
||||||
|
# skip
|
||||||
rundir="$(mktemp -d)"
|
rundir="$(mktemp -d)"
|
||||||
logdir="$(mktemp -d)"
|
logdir="$(mktemp -d)"
|
||||||
rmdir "$logdir"
|
rmdir "$logdir"
|
||||||
@@ -110,7 +112,6 @@
|
|||||||
@test "-d logs multiple requests to multiple urls to multiple custom log files" {
|
@test "-d logs multiple requests to multiple urls to multiple custom log files" {
|
||||||
# skip
|
# skip
|
||||||
rundir="$(mktemp -d)"
|
rundir="$(mktemp -d)"
|
||||||
echo $rundir
|
|
||||||
pwd="$PWD"
|
pwd="$PWD"
|
||||||
cd "$rundir" && run "$pwd/ttfb" -n2 -l "$rundir/custom.log" example.com example.com/hello-world
|
cd "$rundir" && run "$pwd/ttfb" -n2 -l "$rundir/custom.log" example.com example.com/hello-world
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
@@ -119,3 +120,12 @@
|
|||||||
[ $(grep " 200 OK" "$rundir/example_com-custom.log" | wc -l) -eq 2 ]
|
[ $(grep " 200 OK" "$rundir/example_com-custom.log" | wc -l) -eq 2 ]
|
||||||
[ $(grep " 404 Not Found" "$rundir/example_com_hello_world-custom.log" | wc -l) -eq 2 ]
|
[ $(grep " 404 Not Found" "$rundir/example_com_hello_world-custom.log" | wc -l) -eq 2 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "pass custom curl options via our -o option" {
|
||||||
|
# This test passes -k to curl, so it can successfully
|
||||||
|
# call https://self-signed.badssl.com which has a self-signed certificate
|
||||||
|
# which would normally result in a fail
|
||||||
|
# skip
|
||||||
|
run "$pwd/ttfb" -o "-k" https://self-signed.badssl.com
|
||||||
|
[[ "$output" != "0" ]]
|
||||||
|
}
|
||||||
|
|||||||
8
ttfb
8
ttfb
@@ -100,13 +100,15 @@ DEBUG=""
|
|||||||
LOG=""
|
LOG=""
|
||||||
NUM_REQUESTS=0
|
NUM_REQUESTS=0
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
|
options=()
|
||||||
|
|
||||||
while getopts ":n:dl:v" OPTION
|
while getopts "dl:n:o:v" OPTION
|
||||||
do
|
do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
d) DEBUG=1 ;;
|
d) DEBUG=1 ;;
|
||||||
l) LOG="$OPTARG" ;;
|
l) LOG="$OPTARG" ;;
|
||||||
n) NUM_REQUESTS=$OPTARG ;;
|
n) NUM_REQUESTS=$OPTARG ;;
|
||||||
|
o) options+=("$(echo $OPTARG | xargs)") ;;
|
||||||
v) VERBOSE=1 ;;
|
v) VERBOSE=1 ;;
|
||||||
\?) show_usage
|
\?) show_usage
|
||||||
exit 1
|
exit 1
|
||||||
@@ -143,16 +145,12 @@ LOG=$(basename "$LOG")
|
|||||||
|
|
||||||
DEBUG=${DEBUG:-0}
|
DEBUG=${DEBUG:-0}
|
||||||
|
|
||||||
options=()
|
|
||||||
options+=(-o /dev/null)
|
options+=(-o /dev/null)
|
||||||
options+=(-s)
|
options+=(-s)
|
||||||
options+=(-L)
|
options+=(-L)
|
||||||
options+=($HTTP_VERSION)
|
options+=($HTTP_VERSION)
|
||||||
options+=(-H 'Cache-Control: no-cache')
|
options+=(-H 'Cache-Control: no-cache')
|
||||||
options+=(-w 'echo DNS lookup: %{time_namelookup} TLS handshake: %{time_appconnect} TTFB including connection: %{time_starttransfer} TTFB: $(echo %{time_starttransfer} - %{time_appconnect} | bc) Total time: %{time_total} \n')
|
options+=(-w 'echo DNS lookup: %{time_namelookup} TLS handshake: %{time_appconnect} TTFB including connection: %{time_starttransfer} TTFB: $(echo %{time_starttransfer} - %{time_appconnect} | bc) Total time: %{time_total} \n')
|
||||||
if [ $DEBUG -eq 1 ]; then
|
|
||||||
options+=(-D "${LOG_DIRECTORY}/${LOG}")
|
|
||||||
fi
|
|
||||||
|
|
||||||
for URL in $URLS; do
|
for URL in $URLS; do
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user