Wednesday, April 20, 2011

Cross Origin Resource Sharing - CORs

              With advancement of web , Ajax is playing an important role in most of website or web application . One of common restrictions is same -origin policy within browsers due to but obvious security reasons. What we mean by [violating same origin] or cross site request  - "Cross-site HTTP requests are HTTP requests for resources from a different domain ,different port, different sceheme than the domain of the resource making the request.  For instance, a resource loaded from Domain X (http://vvishal.com) such as an HTML web page, makes a request for a resource on Domain Y (http://vvishal.me)". 
Ref : https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript


             Web Developers had been trying work around for this by various means setting up proxies , server side proxies .  At this point of time community of developer outcried a native way of doing cross domain Ajax Request . Cross Origin Resource Sharing - CORS evolved at this point of time .Internet Explorer 8+, Firefox 3.5+, Safari 4+, and Chrome supports CORS , Opera till 10.63 was not suppoting CORS.


             In Simple terms , the basic idea of CORS is to modify HTTP headers from client and server side to enable communication between two. This makes server and client know about each other and recognize the needs , Success , Fail etc. Header plays an important role the handshake between client and server and the informations needed to be exchanged.


Read More:
http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
http://arunranga.com/examples/access-control/
https://developer.mozilla.org/En/HTTP_access_control