Refactor PrestashopClient to enhance header configuration and improve query parameter encoding
This commit is contained in:
@@ -30,7 +30,17 @@ public class PrestashopClient {
|
|||||||
.encodeToString((apiKey + ":").getBytes(StandardCharsets.UTF_8));
|
.encodeToString((apiKey + ":").getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
this.client = RestClient.builder()
|
this.client = RestClient.builder()
|
||||||
.defaultHeader(HttpHeaders.AUTHORIZATION, "Basic " + basicAuth)
|
.baseUrl(baseUrl)
|
||||||
|
.defaultHeaders(headers -> {
|
||||||
|
// Authentification PrestaShop via Basic Auth : key en user, mdp vide
|
||||||
|
headers.setBasicAuth(apiKey, "");
|
||||||
|
|
||||||
|
// IMPORTANT : User-Agent “neutre”
|
||||||
|
headers.set(HttpHeaders.USER_AGENT, "curl/8.10.1");
|
||||||
|
|
||||||
|
// Accept JSON
|
||||||
|
headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.ALL));
|
||||||
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
log.info("[PrestaShop] Base URL = {}", baseUrl);
|
log.info("[PrestaShop] Base URL = {}", baseUrl);
|
||||||
@@ -58,8 +68,10 @@ public class PrestashopClient {
|
|||||||
if (values == null || values.isEmpty()) continue;
|
if (values == null || values.isEmpty()) continue;
|
||||||
|
|
||||||
for (String rawValue : values) {
|
for (String rawValue : values) {
|
||||||
if (first) { sb.append('?'); first = false; }
|
if (first) {
|
||||||
else sb.append('&');
|
sb.append('?');
|
||||||
|
first = false;
|
||||||
|
} else sb.append('&');
|
||||||
|
|
||||||
// encode la clé
|
// encode la clé
|
||||||
sb.append(URLEncoder.encode(key, StandardCharsets.UTF_8));
|
sb.append(URLEncoder.encode(key, StandardCharsets.UTF_8));
|
||||||
|
|||||||
Reference in New Issue
Block a user