Skip to content

Commit

Permalink
Merge pull request #1267 from akto-api-security/hotfix/fix_http2_prot…
Browse files Browse the repository at this point in the history
…ocol

Enable http2 protocol for only grpc
  • Loading branch information
shivam-rawat-akto authored Jul 11, 2024
2 parents 7809d35 + 513ebec commit f5bfe44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/utils/src/main/java/com/akto/testing/ApiExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static OriginalHttpResponse sendRequest(OriginalHttpRequest request, bool
request.setUrl(url);

Request.Builder builder = new Request.Builder();
String type = request.getType();
String type = request.findContentType();
// add headers
List<String> forbiddenHeaders = Arrays.asList("content-length", "accept-encoding");
Map<String, List<String>> headersMap = request.getHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.akto.dto.RawApi;
import com.akto.dto.testing.TestingRunResult;
import com.akto.util.HttpRequestResponseUtils;
import com.akto.util.http_util.CoreHTTPClient;

import okhttp3.*;
Expand Down Expand Up @@ -43,12 +44,12 @@ private HTTPClientHandler(boolean isSaas) {
clientWithFollowRedirect = builder(true, readTimeout).build();
}

public OkHttpClient getNewDebugClient(boolean isSaas, boolean followRedirects, List<TestingRunResult.TestLog> testLogs, String requestProtocol) {
public OkHttpClient getNewDebugClient(boolean isSaas, boolean followRedirects, List<TestingRunResult.TestLog> testLogs, String contentType) {
if(isSaas) readTimeout = 60;
OkHttpClient.Builder builder = builder(followRedirects, readTimeout)
.addInterceptor(new NormalResponseInterceptor(testLogs))
.addNetworkInterceptor(new NetworkResponseInterceptor(testLogs));
if ("HTTP/2".equalsIgnoreCase(requestProtocol)) {
if (contentType != null && contentType.contains(HttpRequestResponseUtils.GRPC_CONTENT_TYPE)) {
builder.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
}
return builder.build();
Expand Down Expand Up @@ -142,8 +143,8 @@ public static void initHttpClientHandler(boolean isSaas) {
}
}

public OkHttpClient getHTTPClient (boolean followRedirect, String requestProtocol) {
if ("HTTP/2".equalsIgnoreCase(requestProtocol)) {
public OkHttpClient getHTTPClient (boolean followRedirect, String contentType) {
if (contentType != null && contentType.contains(HttpRequestResponseUtils.GRPC_CONTENT_TYPE)) {
if (followRedirect) {
return http2ClientWithFollowRedirect;
}
Expand Down

0 comments on commit f5bfe44

Please sign in to comment.