File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
AndroidSDKCore/src/main/java/com/leanplum/internal/http Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -91,11 +91,31 @@ protected void initConnection(
9191 Must include the phrase `gzip` in the `User-Agent` header
9292 https://cloud.google.com/appengine/kb/
9393 */
94- urlConnection .setRequestProperty ("User-Agent" , createUserAgentValue ());
94+ urlConnection .setRequestProperty ("User-Agent" , createUserAgent ());
9595 urlConnection .setRequestProperty ("Accept-Encoding" , Constants .LEANPLUM_SUPPORTED_ENCODING );
9696 }
9797
98- private String createUserAgentValue () {
98+ /**
99+ * Currently Android uses OkHttp as an HTTP client. We need to remove invalid characters from
100+ * the User-Agent value according to checkValue(String, String) from:
101+ *
102+ * https://github.com/square/okhttp/blob/dabbd56572089cfef00d358edcc87b3f5c73e580/okhttp/src/main/kotlin/okhttp3/Headers.kt#L431
103+ */
104+ private String createUserAgent () {
105+ String userAgentString = createUserAgentString ();
106+ StringBuilder result = new StringBuilder ();
107+
108+ // Removing invalid characters
109+ for (int i = 0 ; i < userAgentString .length (); i ++) {
110+ char c = userAgentString .charAt (i );
111+ if (c == '\t' || ('\u0020' <= c && c <= '\u007e' )) {
112+ result .append (c );
113+ }
114+ }
115+ return result .toString ();
116+ }
117+
118+ private String createUserAgentString () {
99119 Context context = Leanplum .getContext ();
100120
101121 return Util .getApplicationName (context )
You can’t perform that action at this time.
0 commit comments