- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
86 lines
3.9 KiB
Java
86 lines
3.9 KiB
Java
package com.amazonaws.http;
|
|
|
|
import com.amazonaws.ClientConfiguration;
|
|
import com.amazonaws.Request;
|
|
import com.amazonaws.util.HttpUtils;
|
|
import com.amazonaws.util.StringUtils;
|
|
import com.facebook.internal.security.CertificateUtil;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.InputStream;
|
|
import java.net.URI;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.apache.http.protocol.HTTP;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class HttpRequestFactory {
|
|
public HttpRequest createHttpRequest(Request request, ClientConfiguration clientConfiguration, ExecutionContext executionContext) {
|
|
String appendUri;
|
|
URI endpoint = request.getEndpoint();
|
|
boolean z = true;
|
|
if (request.getEncodedUriResourcePath() != null) {
|
|
appendUri = HttpUtils.appendUriEncoded(endpoint.toString(), request.getEncodedUriResourcePath());
|
|
} else {
|
|
appendUri = HttpUtils.appendUri(endpoint.toString(), request.getResourcePath(), true);
|
|
}
|
|
String encodeParameters = HttpUtils.encodeParameters(request);
|
|
HttpMethodName httpMethod = request.getHttpMethod();
|
|
boolean z2 = request.getContent() != null;
|
|
HttpMethodName httpMethodName = HttpMethodName.POST;
|
|
if (httpMethod == httpMethodName && !z2) {
|
|
z = false;
|
|
}
|
|
if (encodeParameters != null && z) {
|
|
appendUri = appendUri + "?" + encodeParameters;
|
|
}
|
|
HashMap hashMap = new HashMap();
|
|
configureHeaders(hashMap, request, executionContext, clientConfiguration);
|
|
InputStream content = request.getContent();
|
|
HttpMethodName httpMethodName2 = HttpMethodName.PATCH;
|
|
if (httpMethod == httpMethodName2) {
|
|
hashMap.put("X-HTTP-Method-Override", httpMethodName2.toString());
|
|
httpMethod = httpMethodName;
|
|
}
|
|
if (httpMethod == httpMethodName && request.getContent() == null && encodeParameters != null) {
|
|
byte[] bytes = encodeParameters.getBytes(StringUtils.UTF8);
|
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
|
hashMap.put(HTTP.CONTENT_LEN, String.valueOf(bytes.length));
|
|
content = byteArrayInputStream;
|
|
}
|
|
if (clientConfiguration.isEnableGzip() && hashMap.get("Accept-Encoding") == null) {
|
|
hashMap.put("Accept-Encoding", "gzip");
|
|
} else {
|
|
hashMap.put("Accept-Encoding", HTTP.IDENTITY_CODING);
|
|
}
|
|
HttpRequest httpRequest = new HttpRequest(httpMethod.toString(), URI.create(appendUri), hashMap, content);
|
|
httpRequest.setStreaming(request.isStreaming());
|
|
return httpRequest;
|
|
}
|
|
|
|
public final void configureHeaders(Map map, Request request, ExecutionContext executionContext, ClientConfiguration clientConfiguration) {
|
|
URI endpoint = request.getEndpoint();
|
|
String host = endpoint.getHost();
|
|
if (HttpUtils.isUsingNonDefaultPort(endpoint)) {
|
|
host = host + CertificateUtil.DELIMITER + endpoint.getPort();
|
|
}
|
|
map.put(HTTP.TARGET_HOST, host);
|
|
for (Map.Entry entry : request.getHeaders().entrySet()) {
|
|
map.put(entry.getKey(), entry.getValue());
|
|
}
|
|
if (map.get("Content-Type") == null || ((String) map.get("Content-Type")).isEmpty()) {
|
|
map.put("Content-Type", "application/x-www-form-urlencoded; charset=" + StringUtils.lowerCase("UTF-8"));
|
|
}
|
|
if (executionContext == null || executionContext.getContextUserAgent() == null) {
|
|
return;
|
|
}
|
|
map.put("User-Agent", createUserAgentString(clientConfiguration, executionContext.getContextUserAgent()));
|
|
}
|
|
|
|
public final String createUserAgentString(ClientConfiguration clientConfiguration, String str) {
|
|
if (clientConfiguration.getUserAgent().contains(str)) {
|
|
return clientConfiguration.getUserAgent();
|
|
}
|
|
return clientConfiguration.getUserAgent() + " " + str;
|
|
}
|
|
}
|