#!/bin/bash

# A headerdump generated by curl contains multiple headers if "redirect follow" is enabled.
# This script filters the last headers in the header dump file $1

#if [ $# -ne 1 ]
#then
#	echo "Syntax: $0 <headerdump>"
#	exit 1
#fi

split=();
newl=0;
while read line
do
	line=`echo $line | tr -d "\r"`;
	if [ "$line" == "" ]
	then
		newl=1;
	else
		if [ $newl -eq 1 ]
		then
			split=();
			newl=0;
		fi
		split=("${split[@]}" "$line");
	fi
#done < "$1"
done

for x in "${split[@]}"
do
	echo "$x"
done
