Features: p:http-request

http-request-061 (AB)

Tests that document property headers are only used if the headers option doesn’t specify a header with the same name.

Test is expected to pass.

The pipeline

<p:declare-step xmlns:chttp="http://www.w3.org/ns/xproc-http"
                xmlns:err="http://www.w3.org/ns/xproc-error" xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:output port="result"/>
   <p:option name="WHOST"
             select="'http://localhost:8246'" static="true"/>
   <p:http-request name="one"
                   href="{$WHOST}/service/echoheaders" method="post"
                   headers="map{'header' : 'value1'}">
      <p:with-input>
         <p:inline>
            <doc/>
         </p:inline>
      </p:with-input>
   </p:http-request>
   <p:http-request name="two"
                   href="{$WHOST}/service/echoheaders" method="post">
      <p:with-input>
         <p:inline document-properties="map{'chttp:HEADER' : 'value2'}">
            <doc/>
         </p:inline>
      </p:with-input>
   </p:http-request>
   <p:http-request name="three"
                   href="{$WHOST}/service/echoheaders" method="post"
                   headers="map{'header' : 'value1'}">
      <p:with-input>
         <p:inline document-properties="map{'chttp:HEADER' : 'value2'}">
            <doc/>
         </p:inline>
      </p:with-input>
   </p:http-request>
   <p:wrap-sequence wrapper="headers">
      <p:with-input port="source"
                    pipe="@one @two @three"/>
   </p:wrap-sequence>
</p:declare-step>

Result

<headers xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <headers>
      <header name="ACCEPT_ENCODING"
              value="gzip, x-gzip, deflate, br"/>
      <header name="CONNECTION" value="keep-alive"/>
      <header name="HEADER" value="value1"/>
      <header name="HOST" value="apache2"/>
      <header name="USER_AGENT"
              value="Apache-HttpClient/5.3.1 (Java/21.0.2)"/>
   </headers>
   <headers>
      <header name="ACCEPT_ENCODING"
              value="gzip, x-gzip, deflate, br"/>
      <header name="CONNECTION" value="keep-alive"/>
      <header name="HEADER" value="value2"/>
      <header name="HOST" value="apache2"/>
      <header name="USER_AGENT"
              value="Apache-HttpClient/5.3.1 (Java/21.0.2)"/>
   </headers>
   <headers>
      <header name="ACCEPT_ENCODING"
              value="gzip, x-gzip, deflate, br"/>
      <header name="CONNECTION" value="keep-alive"/>
      <header name="HEADER" value="value1"/>
      <header name="HOST" value="apache2"/>
      <header name="USER_AGENT"
              value="Apache-HttpClient/5.3.1 (Java/21.0.2)"/>
   </headers>
</headers>

Schematron checks

<s:schema xmlns:err="http://www.w3.org/ns/xproc-error"
          xmlns:s="http://purl.oclc.org/dsdl/schematron" xmlns:t="http://xproc.org/ns/testsuite/3.0"
          queryBinding="xslt2">
   <s:pattern>
      <s:rule context="/">
         <s:assert test="headers">The root element is not 'doc'.</s:assert>
      </s:rule>
      <s:rule context="/headers">
         <s:assert test="count(headers)=3">Wrong number of responses.</s:assert>
         <s:assert test="headers[1]/header[@name='HEADER']/@value = 'value1'">First request gets incorrect header value.</s:assert>
         <s:assert test="headers[2]/header[@name='HEADER']/@value = 'value2'">Second request gets incorrect header value.</s:assert>
         <s:assert test="headers[3]/header[@name='HEADER']/@value = 'value1'">Third request gets incorrect header value.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

23 May 2025, Norm Tovey-Walsh
Added static options for web server host and port.
10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
18 Mar 2020, Norman Tovey-Walsh
Changed the header to be in the correct namespace. Changed the test so that it passes as the spec now explicitly states that the comparisons must be performed in a case-insensitive manner.
14 Jan 2020, Achim Berndzen
Added new tests for p:http-request.