Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set English locale for toLowerCase methods to fix #573 dotless i problem #799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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