Completed
Pull Request — master (#164)
by Sander
52s
created

js/ui/popup/factories/httpsTester.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 42
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 42
rs 10
wmc 6
mnd 1
bc 6
fnc 5
bpm 1.2
cpm 1.2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.factory(ꞌHttpsTestꞌ) 0 31 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
        return tester;
41
    }]);
42
}());
43