|
6 | 6 | import com.futurist_labs.android.base_library.repository.persistence.BaseJsonParser; |
7 | 7 | import com.futurist_labs.android.base_library.utils.LogUtils; |
8 | 8 |
|
9 | | -import javax.net.ssl.*; |
10 | | -import java.io.*; |
11 | | -import java.net.*; |
| 9 | +import java.io.BufferedReader; |
| 10 | +import java.io.DataOutputStream; |
| 11 | +import java.io.File; |
| 12 | +import java.io.FileInputStream; |
| 13 | +import java.io.FileOutputStream; |
| 14 | +import java.io.IOException; |
| 15 | +import java.io.InputStream; |
| 16 | +import java.io.InputStreamReader; |
| 17 | +import java.io.OutputStream; |
| 18 | +import java.net.HttpURLConnection; |
| 19 | +import java.net.MalformedURLException; |
| 20 | +import java.net.ProtocolException; |
| 21 | +import java.net.URL; |
| 22 | +import java.net.URLEncoder; |
12 | 23 | import java.security.KeyManagementException; |
13 | 24 | import java.security.NoSuchAlgorithmException; |
14 | 25 | import java.util.ArrayList; |
15 | 26 | import java.util.HashMap; |
16 | 27 | import java.util.Iterator; |
17 | 28 | import java.util.Map; |
18 | 29 |
|
| 30 | +import javax.net.ssl.HostnameVerifier; |
| 31 | +import javax.net.ssl.HttpsURLConnection; |
| 32 | +import javax.net.ssl.SSLContext; |
| 33 | +import javax.net.ssl.SSLSession; |
| 34 | +import javax.net.ssl.TrustManager; |
| 35 | +import javax.net.ssl.X509TrustManager; |
| 36 | + |
19 | 37 |
|
20 | 38 | /** |
21 | 39 | * Created by Galeen on 18.1.2016 г.. |
@@ -140,11 +158,11 @@ static NetworkResponse sendPost(String endpoint, String params, String authToken |
140 | 158 |
|
141 | 159 | private static void addMainHeaders(final String authToken, final HttpURLConnection conn) { |
142 | 160 | if (authToken != null) { |
143 | | - conn.setRequestProperty(NetConstants.HEADER_AUTHORIZATION, authToken); |
| 161 | + conn.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), authToken); |
144 | 162 | } |
145 | 163 |
|
146 | | - if (NetConstants.SHOULD_ADD_LOCALE) { |
147 | | - conn.setRequestProperty(NetConstants.HEADER_LOCALE_FIELD, BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldValue()); |
| 164 | + if (BaseLibraryConfiguration.getInstance().isAddLocale()) { |
| 165 | + conn.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldName(), BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldValue()); |
148 | 166 | } |
149 | 167 |
|
150 | 168 | if (BaseLibraryConfiguration.getInstance().getHeaderOS() != null) { |
@@ -231,10 +249,10 @@ static NetworkResponse sendAuthenticatedGet(String serverUrl, String token, Map< |
231 | 249 | headers = new HashMap<>(); |
232 | 250 | } |
233 | 251 | if (token != null) { |
234 | | - headers.put(NetConstants.HEADER_AUTHORIZATION, token); |
| 252 | + headers.put(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), token); |
235 | 253 | } |
236 | | - if (NetConstants.SHOULD_ADD_LOCALE) { |
237 | | - headers.put(NetConstants.HEADER_LOCALE_FIELD, |
| 254 | + if (BaseLibraryConfiguration.getInstance().isAddLocale()) { |
| 255 | + headers.put(BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldName(), |
238 | 256 | BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldValue()); |
239 | 257 | } |
240 | 258 | return sendGet(serverUrl, params, headers); |
@@ -336,9 +354,9 @@ static NetworkResponse postFile(String urlLink, File uploadFile, String token, M |
336 | 354 | httpUrlConnection.setRequestProperty( |
337 | 355 | "Content-Type", "multipart/form-data;boundary=" + boundary); |
338 | 356 | // if (token != null) |
339 | | -// httpUrlConnection.setRequestProperty(NetConstants.HEADER_AUTHORIZATION, token); |
340 | | - if (NetConstants.SHOULD_ADD_LOCALE) { |
341 | | - httpUrlConnection.setRequestProperty(NetConstants.HEADER_LOCALE_FIELD, |
| 357 | +// httpUrlConnection.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), token); |
| 358 | + if (BaseLibraryConfiguration.getInstance().isAddLocale()) { |
| 359 | + httpUrlConnection.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldName(), |
342 | 360 | BaseLibraryConfiguration.getInstance().getHeaderLocaleFieldValue()); |
343 | 361 | } |
344 | 362 | DataOutputStream request = null; |
@@ -419,7 +437,7 @@ static NetworkResponse multipartRequest(String urlTo, Map<String, String> params |
419 | 437 | connection.setUseCaches(false); |
420 | 438 |
|
421 | 439 | if (token != null) { |
422 | | - connection.setRequestProperty(NetConstants.HEADER_AUTHORIZATION, token); |
| 440 | + connection.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), token); |
423 | 441 | } |
424 | 442 | connection.setRequestMethod("POST"); |
425 | 443 | connection.setRequestProperty("Connection", "Keep-Alive"); |
@@ -503,7 +521,7 @@ static NetworkResponse multipartRequest(String urlTo, Map<String, String> params |
503 | 521 | connection.setUseCaches(false); |
504 | 522 |
|
505 | 523 | if (token != null) { |
506 | | - connection.setRequestProperty(NetConstants.HEADER_AUTHORIZATION, token); |
| 524 | + connection.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), token); |
507 | 525 | } |
508 | 526 | connection.setRequestMethod("POST"); |
509 | 527 | connection.setRequestProperty("Connection", "Keep-Alive"); |
@@ -585,7 +603,7 @@ static NetworkResponse downloadFile(String fileURL, File file, String authToken, |
585 | 603 | URL url = new URL(fileURL); |
586 | 604 | HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); |
587 | 605 | if (authToken != null) { |
588 | | - httpConn.setRequestProperty(NetConstants.HEADER_AUTHORIZATION, authToken); |
| 606 | + httpConn.setRequestProperty(BaseLibraryConfiguration.getInstance().getHeaderAuthorizationFieldName(), authToken); |
589 | 607 | } |
590 | 608 |
|
591 | 609 | if (headers != null) { |
|
0 commit comments