# -- headers.test
#
# testing ::rivet::load_headers command
#

set testfilename1 headers.rvt

# We do this in order to always match the version being used.
set httpversion [package require http]

# we don't necessarily rely on the shadow version of the http package
# shipped with rivet. We try to test more consistently the headers
# as they are received by mod_rivet and returned in ::rivet::load_headers 

::tcltest::test headers-1.1 {load_headers test} {
    set headers_list [list Host $host]
    set token [::http::geturl ${urlbase}$testfilename1 -headers $headers_list]
    set nmatches 0
    set page [::http::data $token]

    foreach {header_name header_value} [list Host $host Accept "\\*/\\*" User-Agent "Tcl http client package $httpversion"] {
        set re_exp [subst {^hdrs\\($header_name\\)\\s+=\\s+$header_value\$}]
        incr nmatches [regexp -all -lineanchor $re_exp $page]
    }
    ::http::cleanup $token
    set nmatches
} 3
