Aurelia Fetch client with HEAD method -
i have simple requirement of fetch (http) client within aurelia: make http request url using method 'head' in order determine if resource exists (but without downloading it).
the call easy make:
this.http.fetch('http://the.url/something.jpg', { method: 'head', mode: 'no-cors' }) .then(response => { this.urlisvalid = response.status === 200; }) .catch(error => { ... handle error });
however, fetch client never appears enter .then() method, gets caught .catch().
- if url exists, or there other error reported server (404, 405, 500 etc), error object 'blank' response (i.e. has properties expect, values empty).
- if url invalid error object contains message 'unable fetch'.
i'm sure i'm missing something, isn't obvious what. can offer solution?
this using aurelia 1.0.0 beta.
update: requested headers (as captured chrome) 1 of requests comes through blank..
url exists:
request url:https://xxx/the/url.pdf request method:head status code:200 ok remote address:xx.xx.xx.xx:443 accept-ranges:bytes connection:keep-alive content-length:278188 content-type:application/pdf date:mon, 08 feb 2016 00:12:21 gmt etag:"955492e4afe7b2199e15cfafd747df27" last-modified:sun, 13 dec 2015 01:20:37 gmt server:amazons3 via:1.1 xxxxxxx.cloudfront.net (cloudfront) x-amz-cf-id:g7dk2pgwdnrkaznkkovjm0luyb78dvdizlb26x-mgbzi8bc9oua75q== x-cache:miss cloudfront
403:
request url:https://xxx/invalid/file.pdf request method:head status code:403 forbidden remote address:xx.xx.xx.xx:443 connection:keep-alive content-type:application/xml date:mon, 08 feb 2016 00:16:12 gmt server:amazons3 via:1.1 xxxxxx.cloudfront.net (cloudfront) x-amz-cf-id:q1id8nggywgebf8prquu5l5a--ekglm7x2glbke-rvv45lxv7ch2vg== x-cache:error cloudfront
your response not blank, opaque. opaque responses can not read , result requesting mode: "no-cors"
. need set mode mode: "cors"
allow responses accessed then, server should set proper cors headers when answering head request.
Comments
Post a Comment