 					res.sendfile "#{config.packageFolder}/#{req.params[0]}/#{req.params[1].toLowerCase()}.tar", (err) -> res.send 404, '404 Not Found' if err?
 				else
 					logger.log "notice", "#{username} tried to download #{req.params[0]}/#{req.params[1].toLowerCase()}"
-					res.setHeader 'WWW-Authenticate', 'Basic realm="Please provide proper username and password to access this package"'
-					res.send 401, 'Please provide proper username and password to access this package'
+					askForCredentials req, res
 			else
 				res.send 404, '404 Not Found'
 		

			# and finally call the callback
			(callback true) if callback?
			
app.all '/', (req, res) ->
	callback = (username) ->
		host = config.basePath ? "#{req.protocol}://#{req.header 'host'}"

				if result
					callback req.auth.username
				else
					askForCredentials req, res
		else
			askForCredentials req, res
	else
		callback ''

