Permalink
Browse files

head events

  • Loading branch information...
1 parent d1f64c7 commit d7031a87fb365b3cdd1fb59976b14c1e7a04e89c @substack committed Sep 23, 2012
Showing with 24 additions and 4 deletions.
  1. +23 −2 lib/handle.js
  2. +1 −2 lib/info.js
View
@@ -71,13 +71,34 @@ handlers.push(function (req, res) {
}
self.exists(repo, function (ex) {
- if (!ex && self.autoCreate) self.create(repo, next)
+ var anyListeners = self.listeners('head').length > 0;
+ var dup = httpDuplex(req, res);
+ dup.exists = ex;
+ dup.accept = function () { dup.emit('accept') };
+ dup.reject = function (code) { dup.emit('reject', code) };
+
+ dup.once('reject', function (code) {
+ dup.statusCode = code || 500;
+ dup.end();
+ });
+
+ if (!ex && self.autoCreate) {
+ dup.once('accept', function () {
+ self.create(repo, next);
+ });
+ self.emit('head', dup);
+ if (!anyListeners) dup.accept();
+ }
else if (!ex) {
res.statusCode = 404;
res.setHeader('content-type', 'text/plain');
res.end('repository not found');
}
- else next()
+ else {
+ dup.once('accept', next);
+ self.emit('head', dup);
+ if (!anyListeners) dup.accept();
+ }
});
});
View
@@ -18,11 +18,10 @@ module.exports = function (opts, req, res) {
});
self.exists(opts.repo, function (ex) {
+ dup.exists = ex;
var anyListeners = self.listeners('info').length > 0;
if (!ex && self.autoCreate) {
- dup.exists = ex;
-
dup.on('accept', function () {
self.create(opts.repo, next)
});

0 comments on commit d7031a8

Please sign in to comment.