Skip to content

Commit

Permalink
Fix the bug: LocalServer replace template tag with htmlsha1 by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonlu committed Nov 9, 2017
1 parent 3eb0b20 commit b264102
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public class SonicServer implements SonicSessionStream.Callback {

final protected SonicSession session;

final protected SonicDataHelper.SessionData sessionData;

final protected Intent requestIntent;

/**
Expand All @@ -72,10 +70,9 @@ public class SonicServer implements SonicSessionStream.Callback {
protected Map<String, List<String>> cachedResponseHeaders;
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

public SonicServer(SonicSession session, SonicDataHelper.SessionData sessionData) {
public SonicServer(SonicSession session, Intent requestIntent) {
this.session = session;
this.sessionData = sessionData;
this.requestIntent = session.createConnectionIntent(sessionData);
this.requestIntent = requestIntent;
connectionImpl = SonicSessionConnectionInterceptor.getSonicSessionConnection(session, requestIntent);
}

Expand All @@ -88,11 +85,6 @@ public SonicServer(SonicSession session, SonicDataHelper.SessionData sessionData
*/
protected int connect() {
long startTime = System.currentTimeMillis();
if (session.config.SUPPORT_CACHE_CONTROL && startTime < sessionData.expiredTime) {
responseCode = HttpURLConnection.HTTP_NOT_MODIFIED; // fix 304 case
return SonicConstants.ERROR_CODE_SUCCESS;
}


int resultCode = connectionImpl.connect();
session.statistics.connectionConnectTime = System.currentTimeMillis();
Expand Down Expand Up @@ -428,6 +420,7 @@ private void separateTemplateAndData() {
}

String eTag = getResponseHeaderField(CUSTOM_HEAD_FILED_ETAG);
String templateTag = getResponseHeaderField(CUSTOM_HEAD_FILED_TEMPLATE_TAG);
if (TextUtils.isEmpty(eTag)) { // When eTag is empty, fill eTag with Sha1
eTag = SonicUtils.getSHA1(serverRsp);
addResponseHeaderFields(CUSTOM_HEAD_FILED_ETAG, eTag);
Expand All @@ -437,7 +430,7 @@ private void separateTemplateAndData() {
if (TextUtils.isEmpty(templateString)) { // The same with htmlString
templateString = serverRsp;
addResponseHeaderFields(CUSTOM_HEAD_FILED_TEMPLATE_TAG, eTag);
} else {
} else if (TextUtils.isEmpty(templateTag)){ // When eTag is empty, fill templateTag with Sha1 of templateString
addResponseHeaderFields(CUSTOM_HEAD_FILED_TEMPLATE_TAG, SonicUtils.getSHA1(templateString));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,14 @@ protected void handleFlow_Connection(String cacheHtml) {
sessionData = SonicDataHelper.getSessionData(id);
}

server = new SonicServer(this, sessionData);
if (config.SUPPORT_CACHE_CONTROL && statistics.connectionFlowStartTime < sessionData.expiredTime) {
if (SonicUtils.shouldLog(Log.DEBUG)) {
SonicUtils.log(TAG, Log.DEBUG, "session(" + sId + ") won't send any request in " + (sessionData.expiredTime - statistics.connectionFlowStartTime) + ".ms");
}
return;
}

server = new SonicServer(this, createConnectionIntent(sessionData));

// Connect to web server
int responseCode = server.connect();
Expand Down Expand Up @@ -1118,7 +1125,7 @@ protected void destroy(boolean force) {
clearSessionData();

if (force || canDestroy()) {
if (null != server) {
if (null != server && !force) {
server.disconnect();
server = null;
}
Expand Down

0 comments on commit b264102

Please sign in to comment.