mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 21:06:09 +03:00
SSO: return response headers
This commit is contained in:
parent
dca16038b9
commit
0fdc57a9e9
1 changed files with 23 additions and 16 deletions
|
@ -3,11 +3,11 @@ package it.niedermann.owncloud.notes.persistence;
|
|||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.nextcloud.android.sso.aidl.NextcloudRequest;
|
||||
import com.nextcloud.android.sso.api.AidlNetworkRequest;
|
||||
import com.nextcloud.android.sso.api.NextcloudAPI;
|
||||
import com.nextcloud.android.sso.api.Response;
|
||||
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
|
||||
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
|
||||
import com.nextcloud.android.sso.helper.SingleAccountHelper;
|
||||
|
@ -17,14 +17,15 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.util.ServerResponse.NoteResponse;
|
||||
import it.niedermann.owncloud.notes.util.ServerResponse.NotesResponse;
|
||||
|
@ -181,26 +182,32 @@ public class NotesClient {
|
|||
|
||||
try {
|
||||
Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString());
|
||||
InputStream inputStream = mNextcloudAPI.performNetworkRequest(nextcloudRequest);
|
||||
Response response = mNextcloudAPI.performNetworkRequest(nextcloudRequest);
|
||||
Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString());
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getInputStream()));
|
||||
String line;
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
inputStream.close();
|
||||
response.getInputStream().close();
|
||||
|
||||
String etag = "";
|
||||
AidlNetworkRequest.PlainHeader eTagHeader = response.getPlainHeader(HEADER_KEY_ETAG);
|
||||
if (eTagHeader != null) {
|
||||
etag = Objects.requireNonNull(eTagHeader.getValue());
|
||||
}
|
||||
|
||||
long lastModified = 0;
|
||||
AidlNetworkRequest.PlainHeader lastModifiedHeader = response.getPlainHeader(HEADER_KEY_LAST_MODIFIED);
|
||||
if (lastModifiedHeader != null)
|
||||
lastModified = new SimpleDateFormat("EEE, d MMM YYYY HH:mm:ss Z").parse((Objects.requireNonNull(lastModifiedHeader.getValue()))).getTime() / 1000;
|
||||
Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")");
|
||||
// return these header fields since they should only be saved after successful processing the result!
|
||||
return new ResponseData(result.toString(), etag, lastModified);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseData("", "", 0); // dummy please change
|
||||
}
|
||||
String etag = "";
|
||||
if (nextcloudRequest.getHeader().get(HEADER_KEY_ETAG) != null) {
|
||||
etag = Objects.requireNonNull(nextcloudRequest.getHeader().get(HEADER_KEY_ETAG)).get(0);
|
||||
}
|
||||
long lastModified = 0;
|
||||
if (nextcloudRequest.getHeader().get(HEADER_KEY_LAST_MODIFIED) != null)
|
||||
lastModified = Long.parseLong(Objects.requireNonNull(nextcloudRequest.getHeader().get(HEADER_KEY_LAST_MODIFIED)).get(0)) / 1000;
|
||||
Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")");
|
||||
// return these header fields since they should only be saved after successful processing the result!
|
||||
return new ResponseData(result.toString(), etag, lastModified);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue