Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add custom XHR support to Polymaps #125

Closed
wants to merge 2 commits into from

1 participant

@chrisdickinson

Allows polymaps users to set or unset custom HTTP headers.

// set a header
org.polymaps.queue.header('X-Requested-With', 'XMLHttpRequest')

// unset a header
org.polymaps.queue.header('X-Requested-With')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/Queue.js
View
14 src/Queue.js
@@ -1,5 +1,5 @@
po.queue = (function() {
- var queued = [], active = 0, size = 6;
+ var queued = [], active = 0, size = 6, headers = {};
function process() {
if ((active >= size) || !queued.length) return;
@@ -26,6 +26,12 @@ po.queue = (function() {
req.overrideMimeType(mimeType);
}
req.open("GET", url, true);
+
+ for(var key in headers) if(headers.hasOwnProperty(key)) {
+ if(headers[key])
+ req.setRequestHeader(key, headers[key])
+ }
+
req.onreadystatechange = function(e) {
if (req.readyState == 4) {
active--;
@@ -99,5 +105,9 @@ po.queue = (function() {
return {abort: abort};
}
- return {text: text, xml: xml, json: json, image: image};
+ function header(header, value) {
+ headers[header] = value
+ }
+
+ return {text: text, xml: xml, json: json, image: image, header:header};
})();
Something went wrong with that request. Please try again.