forked from organicmaps/organicmaps
[andorid] Added authorization header to bookmark dowload request and refactored header's constants
This commit is contained in:
parent
5acf5c35ca
commit
136de6278e
6 changed files with 23 additions and 5 deletions
|
@ -1889,4 +1889,11 @@ Java_com_mapswithme_maps_Framework_nativeBindUser(JNIEnv * env, jclass, jobject
|
|||
e->CallVoidMethod(*listenerRef, callback, static_cast<jboolean>(success));
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeGetAccessToken(JNIEnv * env, jclass)
|
||||
{
|
||||
auto & user = frm()->GetUser();
|
||||
return jni::ToJavaString(env, user.GetAccessToken());
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -507,4 +507,7 @@ public class Framework
|
|||
private static native void nativeDisableAdProvider(int provider, int bannerPlace);
|
||||
|
||||
public static native void nativeBindUser(@NonNull UserBindingListener listener);
|
||||
|
||||
@Nullable
|
||||
public static native String nativeGetAccessToken();
|
||||
}
|
||||
|
|
|
@ -52,9 +52,16 @@ public class BookmarksDownloadManager
|
|||
DownloadManager.Request request = new DownloadManager
|
||||
.Request(dstUri)
|
||||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
.addRequestHeader(HttpClient.USER_AGENT, Framework.nativeGetUserAgent())
|
||||
.addRequestHeader(HttpClient.HEADER_USER_AGENT, Framework.nativeGetUserAgent())
|
||||
.setDestinationInExternalFilesDir(mContext, null, dstUri.getLastPathSegment());
|
||||
|
||||
String accessToken = Framework.nativeGetAccessToken();
|
||||
if (!TextUtils.isEmpty(accessToken))
|
||||
{
|
||||
String headerValue = HttpClient.HEADER_BEARER_PREFFIX + accessToken;
|
||||
request.addRequestHeader(HttpClient.HEADER_AUTHORIZATION, headerValue);
|
||||
}
|
||||
|
||||
String title = makeTitle(srcUri);
|
||||
if (!TextUtils.isEmpty(title))
|
||||
request.setTitle(title);
|
||||
|
|
|
@ -147,7 +147,7 @@ class ChunkTask extends AsyncTask<Void, byte[], Integer>
|
|||
urlConnection.setReadTimeout(TIMEOUT_IN_SECONDS * 1000);
|
||||
|
||||
// Set user agent with unique client id
|
||||
urlConnection.setRequestProperty(HttpClient.USER_AGENT, mUserAgent);
|
||||
urlConnection.setRequestProperty(HttpClient.HEADER_USER_AGENT, mUserAgent);
|
||||
|
||||
// Provide authorization credentials
|
||||
String creds = url.getUserInfo();
|
||||
|
|
|
@ -53,12 +53,13 @@ import java.util.zip.InflaterInputStream;
|
|||
|
||||
public final class HttpClient
|
||||
{
|
||||
public static final String HEADER_USER_AGENT = "User-Agent";
|
||||
public static final String HEADER_AUTHORIZATION = "Authorization";
|
||||
public static final String HEADER_BEARER_PREFFIX = "Bearer ";
|
||||
private final static String TAG = HttpClient.class.getSimpleName();
|
||||
// TODO(AlexZ): tune for larger files
|
||||
private final static int STREAM_BUFFER_SIZE = 1024 * 64;
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.NETWORK);
|
||||
public static final String USER_AGENT = "User-Agent";
|
||||
|
||||
|
||||
public static Params run(@NonNull final Params p) throws IOException, NullPointerException
|
||||
{
|
||||
|
|
|
@ -202,7 +202,7 @@ public final class HttpUploader
|
|||
|
||||
private void setHeaders(@NonNull URLConnection connection, long bodyLength)
|
||||
{
|
||||
mHeaders.add(new KeyValue(HttpClient.USER_AGENT, Framework.nativeGetUserAgent()));
|
||||
mHeaders.add(new KeyValue(HttpClient.HEADER_USER_AGENT, Framework.nativeGetUserAgent()));
|
||||
mHeaders.add(new KeyValue("App-Version", BuildConfig.VERSION_NAME));
|
||||
mHeaders.add(new KeyValue("Content-Type", "multipart/form-data; boundary=" + mBoundary));
|
||||
mHeaders.add(new KeyValue("Content-Length", String.valueOf(bodyLength)));
|
||||
|
|
Loading…
Add table
Reference in a new issue