javascript - Fetching HTTP Header Params -


i'm trying write piece of zap code run javascript test http header response of url get. specifically, i'm interested in return status , location (basically, if it's 302, want know redirect location is).

fetch('https://www.example.com/', { method: 'get', redirect: 'manual' })   .then(function(res) {     return res.json();   })   .then(function(json) {     var output = {status: json.status, location: json.headers.get('location')};     callback(null, output);   })   .catch(callback); 

i've tried above (a) test returns rawhtml (which suggests it's following redirect, , (b) output variables in send outbound zap step don't pick useful (again, "raw html", "id", "runtime meta logs", etc. nothing headers).

you may not able access location header due same origin policy in browsers: https://developer.mozilla.org/en-us/docs/web/security/same-origin_policy

furthermore, can't stop ajax call following redirect, may cause issues: how prevent jquery ajax following redirect after post?

it looks using new built-in fetch function: https://developer.mozilla.org/en-us/docs/web/api/fetch_api/using_fetch

if so, in provided example, dont think need .json() call. got code run like below, there no redirect @ example.com not sure how situation handle. also, keep in mind same-origin policy prohibit accessing location header.

var callback = function(a,b){   console.log(a,b) }; fetch('https://www.example.com/', { method: 'get', redirect: 'manual' })   .then(function(res) {      console.log (res)     var output = {status: res.status, location: res.headers.get('location')};     callback(null, output);   })   .catch(callback); 

if control server resource, possibly on server, adding header won't blocked, many sites adding x-location option browsers don't block.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -