SSO: return response headers

This commit is contained in:
tobiasKaminsky 2019-10-24 07:54:32 +02:00
parent dca16038b9
commit 0fdc57a9e9
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7

View file

@ -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);
}
}