Reading headers from the ResponseHeaders / RequestHeaders feature


In the case of integration using the Gate HTTP module and RESTful API, there are situations in which it is necessary to read the headers from the received response, e.g. to obtain the address to which the next request should be sent.

 

To read header values ​​from the ResponseHeaders feature of the HttpRequest object or from the RequestHeaders feature of the HttpListener object:

  • create user features to which header values ​​will be saved:



  • create a script that will read the header values ​​- the ResponseHeaders feature for the HttpRequest object and the RequestHeaders feature for the HttpListener object take the form of a table with name - value pairs in the subsequent indexes, so the script should look like this:

local hdr = HTTP->test_req->ResponseHeaders

for k,v in ipairs(hdr) do

if(v.name=="Location") then
HTTP->hdr_location = v.value
end

if(v.name=="Date") then
HTTP->hdr_date = v.value
end

if(v.name=="X-Content-Type-Options") then
HTTP->hdr_content = v.value
end

end


where:
* Location, Date, X-Content-Type-Options are the names of the headers received,
* hdr_location, hdr_date, hdr_content are user features to which header values ​​are written.

  • assign the previously created script to the OnResponse event of the HttpRequest virtual object or to the OnRequest event of the HttpListener virtual object:

 

After sending the configuration and sending the query, the user characteristics should take the appropriate values: