From 784aa87e0d674e8468af7cfee7ed6b0de71a479f Mon Sep 17 00:00:00 2001 From: Thomas Greiner Date: Fri, 9 May 2014 00:22:03 +0200 Subject: [PATCH] Allow setting header flags on Request creation --- README.md | 1 + lib/client.js | 1 + lib/pending.js | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa526c8..9865690 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ request to finish. (optional, default 4000) * `cache` -- can be false to disable caching, or implement the cache model, or an instance of Cache but with a different store (optional, default platform.cache) + * `header` -- an object containing header flags (optional) There are only two methods diff --git a/lib/client.js b/lib/client.js index ffa66d7..1cdf5cf 100644 --- a/lib/client.js +++ b/lib/client.js @@ -51,6 +51,7 @@ debug = function debug() { var Request = exports.Request = function(opts) { if (!(this instanceof Request)) return new Request(opts); + this.header = opts.header; this.question = opts.question; this.server = opts.server; diff --git a/lib/pending.js b/lib/pending.js index e6c0c06..e339582 100644 --- a/lib/pending.js +++ b/lib/pending.js @@ -100,7 +100,7 @@ var random_integer = function() { SocketQueue.prototype._dequeue = function() { var req = this._pending.pop(); - var id, packet, dnssocket; + var id, packet, dnssocket, k; if (req) { id = random_integer(); @@ -118,6 +118,13 @@ SocketQueue.prototype._dequeue = function() { packet = new Packet(this._socket.remote(req.server)); packet.header.id = id; packet.header.rd = 1; + if (req.header) { + for (k in req.header) { + if (k in packet.header) { + packet.header[k] = req.header[k]; + } + } + } if (req.try_edns) { packet.edns_version = 0;