Conditions | 1 |
Paths | 1 |
Total Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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 |