From b15de12be98d82a82e8890b4b7c2951ee654b8e8 Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Thu, 3 Nov 2016 13:11:35 -0400 Subject: [PATCH] Make invalid_host_header.sh work when HOSTNAME has no port. --- .../automatic/system_tests/invalid_host_header.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pagespeed/automatic/system_tests/invalid_host_header.sh b/pagespeed/automatic/system_tests/invalid_host_header.sh index f956a263f..dc179bd77 100644 --- a/pagespeed/automatic/system_tests/invalid_host_header.sh +++ b/pagespeed/automatic/system_tests/invalid_host_header.sh @@ -1,9 +1,14 @@ start_test Invalid HOST URL does not crash the server. -HOST=$(echo $HOSTNAME | cut -d : -f 1) -PORT=$(echo $HOSTNAME | cut -d : -f 2) +if [[ "$HOSTNAME" == *:* ]]; then + host=$(echo $HOSTNAME | cut -d : -f 1) + port=$(echo $HOSTNAME | cut -d : -f 2) +else + host=$HOSTNAME + port=80 +fi -exec 3<>/dev/tcp/$HOST/$PORT +exec 3<>/dev/tcp/$host/$port echo -e "GET /mod_pagespeed_example/ HTTP/1.1\nHost: 127.0.0.\xEF\xBF\xBD\n" >&3 # Read first line of HTTP response with a timeout of 1 second. # It would be nice to get the whole body with: