Skip to content

Instantly share code, notes, and snippets.

@loadster
Created June 19, 2014 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loadster/6d63a0a845aa58c993d4 to your computer and use it in GitHub Desktop.
Save loadster/6d63a0a845aa58c993d4 to your computer and use it in GitHub Desktop.
Iterate the response headers and check the Content-Type
function validate(response) {
var headers = response.getHeaders();
console.log("The response has " + headers.size() + " headers");
for (var i = 0; i < headers.size(); i++) {
var header = headers.get(i);
if (header.name == "Content-Type") {
if (header.value == "application/json") {
return true; // validation succeeds!
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment