Skip to content

Commit

Permalink
Set English locale for toLowerCase methods to fix joltup#573 dotless …
Browse files Browse the repository at this point in the history
…i problem
  • Loading branch information
eczmustafa committed Jul 10, 2022
1 parent a0b26a2 commit d9a902b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
java.home=/usr/lib/jvm/java-11-openjdk-amd64
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
16 changes: 9 additions & 7 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.HashMap;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -115,6 +116,7 @@ enum ResponseFormat {
boolean timeout = false;
ArrayList<String> redirects = new ArrayList<>();
OkHttpClient client;
Locale httpHeaderLocale = Locale.ENGLISH;

public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, OkHttpClient client, final Callback callback) {
this.method = method.toUpperCase();
Expand Down Expand Up @@ -300,14 +302,14 @@ else if (value.equalsIgnoreCase("utf8"))
responseFormat = ResponseFormat.UTF8;
}
else {
builder.header(key.toLowerCase(), value);
mheaders.put(key.toLowerCase(), value);
builder.header(key.toLowerCase(httpHeaderLocale), value);
mheaders.put(key.toLowerCase(httpHeaderLocale), value);
}
}
}

if(method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch")) {
String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase();
String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase(httpHeaderLocale);

if(rawRequestBodyArray != null) {
requestType = RequestType.Form;
Expand All @@ -323,7 +325,7 @@ else if(cType.isEmpty()) {
|| rawRequestBody.startsWith(RNFetchBlobConst.CONTENT_PREFIX)) {
requestType = RequestType.SingleFile;
}
else if (cType.toLowerCase().contains(";base64") || cType.toLowerCase().startsWith("application/octet")) {
else if (cType.toLowerCase().contains(";base64") || cType.toLowerCase(httpHeaderLocale).startsWith("application/octet")) {
cType = cType.replace(";base64","").replace(";BASE64","");
if(mheaders.containsKey("content-type"))
mheaders.put("content-type", cType);
Expand Down Expand Up @@ -717,7 +719,7 @@ private boolean isBlobResponse(Response resp) {
boolean isCustomBinary = false;
if(options.binaryContentTypes != null) {
for(int i = 0; i< options.binaryContentTypes.size();i++) {
if(ctype.toLowerCase().contains(options.binaryContentTypes.getString(i).toLowerCase())) {
if(ctype.toLowerCase(httpHeaderLocale).contains(options.binaryContentTypes.getString(i).toLowerCase())) {
isCustomBinary = true;
break;
}
Expand All @@ -729,13 +731,13 @@ private boolean isBlobResponse(Response resp) {
private String getHeaderIgnoreCases(Headers headers, String field) {
String val = headers.get(field);
if(val != null) return val;
return headers.get(field.toLowerCase()) == null ? "" : headers.get(field.toLowerCase());
return headers.get(field.toLowerCase(httpHeaderLocale)) == null ? "" : headers.get(field.toLowerCase(Locale.English));
}

private String getHeaderIgnoreCases(HashMap<String,String> headers, String field) {
String val = headers.get(field);
if(val != null) return val;
String lowerCasedValue = headers.get(field.toLowerCase());
String lowerCasedValue = headers.get(field.toLowerCase(httpHeaderLocale));
return lowerCasedValue == null ? "" : lowerCasedValue;
}

Expand Down

0 comments on commit d9a902b

Please sign in to comment.