Skip to content

Commit 9098769

Browse files
committed
Revert PR 276
Add Cache Control Headers for Angular Generator Rest Services
1 parent fce1df9 commit 9098769

File tree

3 files changed

+8
-44
lines changed

3 files changed

+8
-44
lines changed

common/src/main/java/com/genexus/ClientInformation.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,4 @@ static public String getPlatformName()
7373
platformName = SpecificImplementation.Application.getModelContext().getHttpContext().getHeader("DevicePlatform");
7474
return platformName;
7575
}
76-
77-
public final class DeviceTypeEnum {
78-
public static final int iOS = 0;
79-
public static final int Android = 1;
80-
public static final int Blackberry = 2;
81-
public static final int Windows = 3;
82-
public static final int Web = 4;
83-
}
8476
}

common/src/main/java/com/genexus/GXSmartCacheProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void discardUpdates()
6363
// <param name="dateLastModified"></param>
6464
// <param name="dateUpdated"></param>
6565
// <returns>Unknown/Invalid/UpToDate</returns>
66-
static public DataUpdateStatus checkDataStatus(String queryId, Date dateLastModified, Date[] dateUpdated_arr)
66+
static public DataUpdateStatus CheckDataStatus(String queryId, Date dateLastModified, Date[] dateUpdated_arr)
6767
{
6868
return (DataUpdateStatus) provider.CheckDataStatus(queryId, dateLastModified, dateUpdated_arr);
6969
}

java/src/main/java/com/genexus/GxRestService.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -244,58 +244,30 @@ public boolean processHeaders(String queryId, IHttpServletRequest myServletReque
244244
{
245245
setTheme(theme);
246246
}
247-
String eTag = isPostRequest(myServletRequest) ? null : myServletRequest.getHeader("If-Modified-Since");
247+
String etag = myServletRequest.getMethod().equalsIgnoreCase(POST) ? null : myServletRequest.getHeader("If-Modified-Since");
248248
Date dt = Application.getStartDateTime();
249249
Date newDt = new Date();
250250
GXSmartCacheProvider.DataUpdateStatus status;
251251
Date[] newDt_arr = new Date[] { newDt };
252-
if (eTag == null)
252+
if (etag == null)
253253
{
254254
status = GXSmartCacheProvider.DataUpdateStatus.Invalid;
255-
GXSmartCacheProvider.checkDataStatus(queryId, dt, newDt_arr);
255+
GXSmartCacheProvider.CheckDataStatus(queryId, dt, newDt_arr);
256256
}
257257
else
258258
{
259-
dt = HTMLDateToDatetime(eTag);
260-
status = GXSmartCacheProvider.checkDataStatus(queryId, dt, newDt_arr);
259+
dt = HTMLDateToDatetime(etag);
260+
status = GXSmartCacheProvider.CheckDataStatus(queryId, dt, newDt_arr);
261261
}
262262
newDt = newDt_arr[0];
263-
addHeader(myServletResponse, "Last-Modified", DateTimeToHTMLDate(newDt));
264-
addCacheHeaders(myServletResponse);
263+
if (myServletResponse != null) // Temporary: Jersey Service called through AWS Lambda where HttpResponse is null.
264+
myServletResponse.addHeader("Last-Modified", DateTimeToHTMLDate(newDt));
265265
if (status == GXSmartCacheProvider.DataUpdateStatus.UpToDate)
266266
{
267267
return false;
268268
}
269269
return true;
270270
}
271-
272-
private void addCacheHeaders(IHttpServletResponse myServletResponse) {
273-
/*
274-
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
275-
* Specifying no-cache or max-age=0 indicates that
276-
* clients can cache a resource and must revalidate each time before using it.
277-
* This means HTTP request occurs each time, but it can skip downloading HTTP body if the content is valid.
278-
*/
279-
if (ClientInformation.getDeviceType() == ClientInformation.DeviceTypeEnum.Web) {
280-
addHeader(myServletResponse, "Cache-Control", "no-cache, max-age=0");
281-
}
282-
}
283-
284-
boolean isPostRequest(IHttpServletRequest request)
285-
{
286-
return request.getMethod().equalsIgnoreCase(POST);
287-
}
288-
289-
void addHeader(IHttpServletResponse response, String headerName, String headerValue)
290-
{
291-
if (response != null) {
292-
// Temporary: Jersey Service called through AWS Lambda where HttpResponse is null.
293-
response.addHeader(headerName, headerValue);
294-
}
295-
else {
296-
logger.warn("Could add HttpHeader to Response");
297-
}
298-
}
299271

300272
Date HTMLDateToDatetime(String s)
301273
{

0 commit comments

Comments
 (0)