@@ -36,39 +36,25 @@ def save_pactfile_to_tmp pact, name
36
36
end
37
37
38
38
def render_pact ( uri_string , options )
39
- uri_obj = URI ( windows_safe ( uri_string ) )
40
- if uri_obj . userinfo
41
- options [ :username ] = uri_obj . user unless options [ :username ]
42
- options [ :password ] = uri_obj . password unless options [ :password ]
43
- end
44
- get ( uri_obj , options )
39
+ local? ( uri_string ) ? get_local ( uri_string , options ) : get_remote_with_retry ( uri_string , options )
45
40
end
46
41
47
42
private
48
-
49
- def get ( uri , options )
50
- local? ( uri ) ? get_local ( uri , options ) : get_remote_with_retry ( uri , options )
51
- end
52
-
43
+
53
44
def local? uri
54
- !uri . host
45
+ !uri . start_with? ( "http://" , "https://" )
55
46
end
56
47
57
- def get_local ( uri , _ )
58
- File . read uri . to_s
48
+ def get_local ( filepath , _ )
49
+ File . read windows_safe ( filepath )
59
50
end
60
51
61
- def get_remote ( uri , options )
62
- request = Net ::HTTP ::Get . new ( uri )
63
- request . basic_auth ( options [ :username ] , options [ :password ] ) if options [ :username ]
64
- Net ::HTTP . start ( uri . host , uri . port , use_ssl : uri . scheme == 'https' ) do |http |
65
- http . open_timeout = options [ :open_timeout ] || OPEN_TIMEOUT
66
- http . read_timeout = options [ :read_timeout ] || READ_TIMEOUT
67
- http . request ( request )
68
- end
69
- end
70
-
71
- def get_remote_with_retry ( uri , options )
52
+ def get_remote_with_retry ( uri_string , options )
53
+ uri = URI ( uri_string )
54
+ if uri . userinfo
55
+ options [ :username ] = uri . user unless options [ :username ]
56
+ options [ :password ] = uri . password unless options [ :password ]
57
+ end
72
58
( ( options [ :retry_limit ] || RETRY_LIMIT ) + 1 ) . times do |i |
73
59
begin
74
60
response = get_remote ( uri , options )
@@ -88,6 +74,16 @@ def get_remote_with_retry(uri, options)
88
74
end
89
75
end
90
76
end
77
+
78
+ def get_remote ( uri , options )
79
+ request = Net ::HTTP ::Get . new ( uri )
80
+ request . basic_auth ( options [ :username ] , options [ :password ] ) if options [ :username ]
81
+ Net ::HTTP . start ( uri . host , uri . port , use_ssl : uri . scheme == 'https' ) do |http |
82
+ http . open_timeout = options [ :open_timeout ] || OPEN_TIMEOUT
83
+ http . read_timeout = options [ :read_timeout ] || READ_TIMEOUT
84
+ http . request ( request )
85
+ end
86
+ end
91
87
92
88
def success? ( response )
93
89
response . code . to_i == 200
0 commit comments