From 3fc44310cd716220905ea522ad3be412f967b13e Mon Sep 17 00:00:00 2001 From: Marcus Westin Date: Mon, 15 Aug 2011 23:30:16 -0700 Subject: [PATCH] Use std.client to parse user agents, and ensure that the client is at least version 5 if it's ios --- src/server/Server.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/server/Server.js b/src/server/Server.js index 874a7e6..209d414 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -7,7 +7,8 @@ var Class = require('std/Class'), fs = require('fs'), path = require('path'), time = require('std/time'), - Response = require('./Response') + Response = require('./Response'), + client = require('std/client') module.exports = Class(function() { @@ -57,11 +58,11 @@ module.exports = Class(function() { /* Request handlers ******************/ this._handleRootRequest = function(match, req, res) { - var userAgent = req.headers['user-agent'] + var reqClient = client.parse(req.headers['user-agent']) var location = - userAgent.match('iPad') ? 'iphone' - : userAgent.match('iPhone') ? 'iphone' - : userAgent.match('iPod') ? 'iphone' + reqClient.isIPad ? 'iphone' + : reqClient.isIPhone ? 'iphone' + : reqClient.isIPod ? 'iphone' : 'iphone' res @@ -75,6 +76,11 @@ module.exports = Class(function() { this._handleClientHTMLRequest = function(match, req, res) { var clientPathBase = this._clients[match[1]] if (!clientPathBase) { return this._sendError(res, 404) } + var reqClient = client.parse(req.headers['user-agent']) + if (reqClient.isIOS && reqClient.osVersion < 5.0) { + this._sendJSError(res, 'Aw shucks. You need iOS 5.0') + return + } this._sendStaticFile(this._currentVersionLink, 'client/' + clientPathBase, 'html', res) } @@ -102,6 +108,12 @@ module.exports = Class(function() { this._getStaticPath = function(version, pathBase, extension) { return this._staticDir+'/'+version+'/'+pathBase+'.'+extension } + + this._sendJSError = function(res, message) { + res + .cache(3 * time.hours) + .send('', 'text/html') + } }) // function handleImageRequest(req, res) {