Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix

  • Loading branch information...
commit 7dae8a05a1f079cfae014b5e9ff87305abef3d64 1 parent 47eddb8
Tokuhiro Matsuno authored
Showing with 22 additions and 12 deletions.
  1. +2 −2 README.mkdn
  2. +2 −2 eg/server.js
  3. +18 −8 mobileagent.js
4 README.mkdn
View
@@ -7,11 +7,11 @@ But this module can work on browsers.
Usage
------
- var ma = require('mobileagent.js'),
+ var MobileAgent = require('../mobileagent.js'),
http = require('http');
http.createServer(function (req, res) {
- var ma = ma.getMobileAgent(req);
+ var ma = MobileAgent.getMobileAgent(req);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello ' + ma.getCarrierLongName() + '\n');
4 eg/server.js
View
@@ -1,8 +1,8 @@
-var ma = require('../mobileagent.js'),
+var MobileAgent = require('../mobileagent.js'),
http = require('http');
http.createServer(function (req, res) {
- var ma = ma.getMobileAgent(req);
+ var ma = MobileAgent.getMobileAgent(req);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello ' + ma.getCarrierLongName() + '\n');
26 mobileagent.js
View
@@ -455,19 +455,29 @@ var MobileAgentNonMobile = MobileAgentBase.extend({
* @param req request object. It is normally node.js' HTTP request.
**/
function getMobileAgent(req) {
- var ua = req['user-agent'],
- carrier = detectCarrier(ua);
- switch (carrier) {
+ var ua,
+ headers,
+ carrier;
+ if (typeof req === 'object') {
+ if ('headers' in req) {
+ headers = req['headers'];
+ } else {
+ headers = req;
+ }
+ } else {
+ headers = { 'user-agent': req }; // plain string
+ }
+ switch (detectCarrier(headers['user-agent'])) {
case 'I':
- return new MobileAgentDoCoMo(req);
+ return new MobileAgentDoCoMo(headers);
case 'V':
- return new MobileAgentSoftBank(req);
+ return new MobileAgentSoftBank(headers);
case 'E':
- return new MobileAgentEZWeb(req);
+ return new MobileAgentEZWeb(headers);
case 'H':
- return new MobileAgentAirHPhone(req);
+ return new MobileAgentAirHPhone(headers);
default:
- return new MobileAgentNonMobile(req);
+ return new MobileAgentNonMobile(headers);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.