# redir.test --
#
# Tests HTTP redirect handling and redirect-related request semantics.
#
# Copyright (c) 2024-2026 Massimo Manghi
#
# SPDX-License-Identifier: TCL
#
# See the file "license.terms" at the top level of this distribution
# for information on usage and redistribution of this file, and for the
# complete disclaimer of warranties and limitation of liability.
#
# Portions of this file were drafted or revised with AI assistance
# under the direction and review of Massimo Manghi

package require tcltest
namespace import ::tcltest::*

source [file join [file dirname [file normalize [info script]]] support.tcl]
source [file join [file dirname [file normalize [info script]]] http_common.tcl]

::tclcurl::test::load_package

test redir-1.1 {-followlocation follows a five-step redirect chain} -constraints http_server -body {
    ::tclcurl::test::transport_followlocation_chain ::tclcurl::test::server::base_url {}
} -result {0 200 5 1 1}

test redir-1.2 {-maxredirs 4 rejects the fifth redirect} -constraints http_server -body {
    ::tclcurl::test::transport_maxredirs_error ::tclcurl::test::server::base_url {}
} -result {1 1}

test redir-1.3 {-autoreferer sets Referer on the redirected request} -constraints http_server -body {
    ::tclcurl::test::transport_autoreferer ::tclcurl::test::server::base_url {}
} -result {0 1}

test redir-1.4 {without -postredir a POST 301 redirect is retried as GET} -constraints http_server -body {
    ::tclcurl::test::transport_postredir_as_get ::tclcurl::test::server::base_url {}
} -result {0 1}

test redir-1.5 {-postredir 301 keeps POST on a 301 redirect} -constraints http_server -body {
    ::tclcurl::test::transport_postredir_keep_post ::tclcurl::test::server::base_url {}
} -result {0 1}

cleanupTests
