lexicographic sort.

simply copied code from the http package and hacked it to add the
sorting. probably not the most elegant.