js/ui/popup/factories/httpsTester.js   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 46
rs 8.9411

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.factory(ꞌHttpsTestꞌ) 0 35 1
1
(function () {
2
    'use strict';
3
4
    /**
5
     * @ngdoc function
6
     * @name passmanApp.controller:MainCtrl
7
     * @description
8
     * # MainCtrl
9
     * Controller of the passmanApp
10
     */
11
    angular.module('passmanExtension').factory('HttpsTest', ['$http', '$q', function ($http, $q) {
12
        var tester = {};
13
        tester.test = function (url) {
14
            var deferred = $q.defer();
15
            if(url.match(/^https?:\/\//)){
16
                deferred.resolve(url);
17
                return deferred.promise;
18
            }
19
            // first test with https
20
            var protocol = 'https://';
21
22
            var req = {
23
                method: 'GET',
24
                url: protocol+url,
25
                timeout: 500
26
            };
27
28
            $http(req).then(function () {
29
                    // we have https
30
                    deferred.resolve(protocol + url);
31
                },
32
                function () {
33
                    protocol = 'http://';
34
                    // we don't have https
35
                    deferred.reject(protocol + url);
36
                });
37
            return deferred.promise;
38
        };
39
40
        tester.isHTTP = function (url) {
41
            return url.substr(0,5) === 'http:';
42
        };
43
44
        return tester;
45
    }]);
46
}());
47