<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/nw-http-request-131.xml"
        name="nw-http-request-131.xml"
        features="p:http-request"
        expected="pass">
   <t:info xmlns:err="http://www.w3.org/ns/xproc-error">
      <t:title>p:http-request 131 (NW)</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2025-05-23</t:date>
            <t:author>
               <t:name>Norm Tovey-Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Added static options for web server host and port.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2021-09-10</t:date>
            <t:author>
               <t:name>Norman Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Reworked the test. A redirect no longer returns a document, so
there’s no base URI. Instead, the test assumes the base URI will be in the
map produced on the report port.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2021-09-09</t:date>
            <t:author>
               <t:name>Norman Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Test that follow-redirect works as advertised.</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:err="http://www.w3.org/ns/xproc-error">
      <p>Only follow the first <code>follow-redirect</code> redirections.</p>
   </t:description>
   <t:pipeline xmlns:err="http://www.w3.org/ns/xproc-error">
      <p:declare-step xmlns:c="http://www.w3.org/ns/xproc-step"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      exclude-inline-prefixes="c xs"
                      version="3.0">
         <p:output port="result"/>
         <p:option name="WHOST" select="'http://localhost:8246'" static="true"/>
         <p:http-request method="get"
                         href="{$WHOST}/service/this-is-a"
                         parameters="map{'follow-redirect': 2}">
            <p:with-input>
               <p:empty/>
            </p:with-input>
         </p:http-request>
         <p:identity>
            <p:with-input pipe="report"/>
         </p:identity>
         <p:identity name="status">
            <p:with-input>
               <code>{.?status-code}</code>
               <base-uri>{.?base-uri}</base-uri>
               <location>{.?headers?location}</location>
            </p:with-input>
         </p:identity>
         <p:wrap-sequence wrapper="wrap"/>
      </p:declare-step>
   </t:pipeline>
   <t:schematron xmlns:err="http://www.w3.org/ns/xproc-error">
      <s:schema xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://purl.oclc.org/dsdl/schematron"
                queryBinding="xslt2">
         <s:ns prefix="p" uri="http://www.w3.org/ns/xproc"/>
         <s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
         <s:pattern>
            <s:rule context="/*">
               <s:assert test="self::wrap">The root is not wrap.</s:assert>
               <s:assert test="ends-with(base-uri, '/service/this-is-c')">The base-uri is incorrect.</s:assert>
               <s:assert test="code = 302">The status-code is incorrect.</s:assert>
               <s:assert test="ends-with(location, '/service/this-is-d')">The redirect location is incorrect.</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="nw-http-request-131.xml">
      <wrap>
         <code xmlns:err="http://www.w3.org/ns/xproc-error">302</code>
         <base-uri xmlns:err="http://www.w3.org/ns/xproc-error">http://apache2/service/this-is-c</base-uri>
         <location xmlns:err="http://www.w3.org/ns/xproc-error">http://apache2/service/this-is-d</location>
      </wrap>
   </t:result>
</t:test>
