Skip to content

Commit b81a6af

Browse files
author
danf
committed
Outgoing HTTP requests not encoded
1 parent 973df20 commit b81a6af

File tree

4 files changed

+1280
-11
lines changed

4 files changed

+1280
-11
lines changed

impl/src/main/java/com/jfrog/bintray/client/impl/handle/BintrayImpl.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.jfrog.bintray.client.api.BintrayCallException;
44
import com.jfrog.bintray.client.api.MultipleBintrayCallException;
55
import com.jfrog.bintray.client.api.handle.*;
6+
import com.jfrog.bintray.client.impl.util.URIUtil;
67
import org.apache.commons.io.IOUtils;
78
import org.apache.http.*;
89
import org.apache.http.client.ResponseHandler;
@@ -20,8 +21,6 @@
2021

2122
import java.io.IOException;
2223
import java.io.InputStream;
23-
import java.io.UnsupportedEncodingException;
24-
import java.net.URLEncoder;
2524
import java.nio.charset.Charset;
2625
import java.util.*;
2726
import java.util.concurrent.Callable;
@@ -111,7 +110,6 @@ public HttpResponse head(String uri, Map<String, String> headers) throws Bintray
111110
public HttpResponse sign(String uri, Map<String, String> headers, int fileCount) throws BintrayCallException {
112111
HttpPost signRequest = new HttpPost(createUrl(uri));
113112
setHeaders(signRequest, headers);
114-
//Set signRequestTimeoutPerFile * fileCount timeout on request
115113
signRequest.setConfig(RequestConfig.custom().setSocketTimeout(signRequestTimeoutPerFile * fileCount)
116114
.setConnectionRequestTimeout(signRequestTimeoutPerFile * fileCount)
117115
.setConnectTimeout(signRequestTimeoutPerFile * fileCount).build());
@@ -218,15 +216,15 @@ private List<RequestRunner> createPutRequestRunners(Map<String, InputStream> uri
218216
List<RequestRunner> runners = new ArrayList<>();
219217
List<HttpPut> requests = new ArrayList<>();
220218
log.debug("Creating PUT requests and RequestRunners for execution");
221-
for (String uri : uriAndStreamMap.keySet()) {
219+
for (String apiPath : uriAndStreamMap.keySet()) {
222220
HttpPut putRequest;
223221
try {
224-
putRequest = new HttpPut(createUrl(uri));
222+
putRequest = new HttpPut(createUrl(apiPath));
225223
} catch (BintrayCallException bce) {
226224
errors.add(bce);
227225
continue;
228226
}
229-
HttpEntity requestEntity = new InputStreamEntity(uriAndStreamMap.get(uri));
227+
HttpEntity requestEntity = new InputStreamEntity(uriAndStreamMap.get(apiPath));
230228
putRequest.setEntity(requestEntity);
231229
setHeaders(putRequest, headers);
232230
requests.add(putRequest);
@@ -268,12 +266,12 @@ private void collectResults(List<Future<String>> executions, List<BintrayCallExc
268266
}
269267
}
270268

271-
private String createUrl(String uri) throws BintrayCallException {
269+
private String createUrl(String queryPath) throws BintrayCallException {
270+
log.debug("Trying to encode uri: '{}' with base url: {}", queryPath, baseUrl);
272271
try {
273-
log.debug("Trying to encode uri: {}", uri);
274-
return baseUrl + "/" + URLEncoder.encode(uri, "UTF-8");
275-
} catch (UnsupportedEncodingException e) {
276-
throw new BintrayCallException(HttpStatus.SC_BAD_REQUEST, "Malformed url, request will not be executed: ",
272+
return URIUtil.encodeQuery(baseUrl + "/" + queryPath);
273+
} catch (HttpException e) {
274+
throw new BintrayCallException(HttpStatus.SC_BAD_REQUEST, "Malformed url, request will not be sent: ",
277275
e.getMessage());
278276
}
279277
}

0 commit comments

Comments
 (0)