Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Last active December 5, 2017 08:51
Show Gist options
  • Save vladimir-ivanov/4e3456da3ff0701a1ecf4c6ec6156046 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/4e3456da3ff0701a1ecf4c6ec6156046 to your computer and use it in GitHub Desktop.
OPTIONS preflight headers response
.z.pm:{"HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS\r\nAccess-Control-Allow-Headers: Content-Type, Authorization\r\nAccess-Control-Max-Age: 86400\r\nVary: Accept-Encoding, Origin\r\nContent-Length: 0\r\nKeep-Alive: timeout=2, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/plain"}
.z.pp:{.h.hp("foo";"bar")} /add Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS
.z.pw:{show x; show y; y=`one} / needs to return 401 unauthorized
<html>
<body><title>example</title>
<form action="">
<input type="button" value="post" onclick="return postForm()">
</form>
<textarea id="out" rows=25 cols=80></textarea>
<script>
function postForm() {
let opts = {"user": "vlad", "pass": "vlad pass"};
fetch('http://localhost:5001', {
method: 'post',
body: JSON.stringify(opts),
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + btoa("one:pass")
}
}).then(function (response) {
return response.json();
}).then(function (data) {
console.log('Created Gist:', data.html_url);
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment