diff --git a/c/dataservice.c b/c/dataservice.c index b6c61ba74..ebe239071 100644 --- a/c/dataservice.c +++ b/c/dataservice.c @@ -328,7 +328,6 @@ int makeHttpDataServiceUrlMask(DataService *dataService, char *urlMaskBuffer, in return 0; } - /* This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies diff --git a/c/datasetjson.c b/c/datasetjson.c index ffac2f15c..3de2ebf89 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -1032,9 +1032,7 @@ void respondWithDataset(HttpResponse* response, char* absolutePath, int jsonMode jsonPrinter *jPrinter = respondWithJsonPrinter(response); setResponseStatus(response, 200, "OK"); - setContentType(response, "text/json"); - addStringHeader(response,"Server","jdmfws"); - addStringHeader(response,"Transfer-Encoding","chunked"); + setDefaultJSONRESTHeaders(response); writeHeader(response); @@ -1316,9 +1314,8 @@ void respondWithVSAMDataset(HttpResponse* response, char* absolutePath, hashtabl jsonPrinter *jPrinter = respondWithJsonPrinter(response); setResponseStatus(response, 200, "OK"); - setContentType(response, "text/json"); - addStringHeader(response,"Server","jdmfws"); - addStringHeader(response,"Transfer-Encoding","chunked"); + setDefaultJSONRESTHeaders(response); + writeHeader(response); printf("Streaming data for %s\n", absolutePath); @@ -1482,9 +1479,7 @@ void respondWithDatasetMetadata(HttpResponse *response) { jsonPrinter *jPrinter = respondWithJsonPrinter(response); setResponseStatus(response, 200, "OK"); - setContentType(response, "text/json"); - addStringHeader(response, "Server", "jdmfws"); - addStringHeader(response, "Transfer-Encoding", "chunked"); + setDefaultJSONRESTHeaders(response); writeHeader(response); char volser[7]; memset(volser,0,7); @@ -1574,9 +1569,7 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue #ifdef __ZOWE_OS_ZOS HttpRequest *request = response->request; setResponseStatus(response, 200, "OK"); - setContentType(response, "text/json"); - addStringHeader(response, "Server", "jdmfws"); - addStringHeader(response, "Transfer-Encoding", "chunked"); + setDefaultJSONRESTHeaders(response); jsonPrinter *jPrinter = respondWithJsonPrinter(response); writeHeader(response); EntryDataSet *hlqSet; diff --git a/c/httpfileservice.c b/c/httpfileservice.c index 2e6e55c56..818141e38 100644 --- a/c/httpfileservice.c +++ b/c/httpfileservice.c @@ -47,9 +47,7 @@ void response200WithMessage(HttpResponse *response, char *msg) { setResponseStatus(response,200,"OK"); - addStringHeader(response, "Server", "jdmfws"); - setContentType(response, "text/json"); - addStringHeader(response,"Transfer-Encoding","chunked"); + setDefaultJSONRESTHeaders(response); addStringHeader(response,"Connection","close"); writeHeader(response); jsonPrinter *out = respondWithJsonPrinter(response); @@ -560,9 +558,7 @@ void respondWithUnixFileMetadata(HttpResponse *response, char *absolutePath) { jsonPrinter *out = respondWithJsonPrinter(response); setResponseStatus(response, 200, "OK"); - setContentType(response, "text/json"); - addStringHeader(response, "Server", "jdmfws"); - addStringHeader(response, "Transfer-Encoding", "chunked"); + setDefaultJSONRESTHeaders(response); writeHeader(response); int decimalMode = fileUnixMode(&info); diff --git a/c/httpserver.c b/c/httpserver.c index 05d9097cb..b76cd8f81 100644 --- a/c/httpserver.c +++ b/c/httpserver.c @@ -3635,6 +3635,8 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab if (!modified) { setResponseStatus(response, 304, "Not modified"); + addStringHeader(response, "Cache-control", "no-store"); + addStringHeader(response, "Pragma", "no-cache"); addStringHeader(response, "Server", "jdmfws"); addCacheRelatedHeaders(response, mtime, etag); writeHeader(response); @@ -3670,6 +3672,8 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab setResponseStatus(response,200,"OK"); addStringHeader(response,"Server","jdmfws"); + addStringHeader(response, "Cache-control", "no-store"); + addStringHeader(response, "Pragma", "no-cache"); addIntHeader(response,"Content-Length",fileSize); /* Is this safe post-conversion??? */ setContentType(response, mimeType); addCacheRelatedHeaders(response, mtime, etag); @@ -3753,6 +3757,8 @@ void respondWithUnixDirectory(HttpResponse *response, char* absolutePath, int js fflush(stdout); #endif setResponseStatus(response,200,"OK"); + addStringHeader(response, "Cache-control", "no-store"); + addStringHeader(response, "Pragma", "no-cache"); addStringHeader(response,"Server","jdmfws"); addStringHeader(response,"Transfer-Encoding","chunked"); if (jsonMode == 0) { @@ -3782,6 +3788,8 @@ void respondWithUnixFileNotFound(HttpResponse* response, int jsonMode) { addStringHeader(response,"Server","jdmfws"); setContentType(response,"text/plain"); setResponseStatus(response,404,"Not Found"); + addStringHeader(response, "Cache-control", "no-store"); + addStringHeader(response, "Pragma", "no-cache"); addIntHeader(response,"Content-Length",len); writeHeader(response); @@ -3796,15 +3804,19 @@ void respondWithUnixFileNotFound(HttpResponse* response, int jsonMode) { } } +void setDefaultJSONRESTHeaders(HttpResponse *response) { + setContentType(response, "application/json"); + addStringHeader(response, "Server", "jdmfws"); + addStringHeader(response, "Transfer-Encoding", "chunked"); + addStringHeader(response, "Cache-control", "no-store"); + addStringHeader(response, "Pragma", "no-cache"); +} // Response must ALWAYS be finished on return void respondWithJsonError(HttpResponse *response, char *error, int statusCode, char *statusMessage) { jsonPrinter *out = respondWithJsonPrinter(response); - - setContentType(response, "text/json"); setResponseStatus(response,statusCode,statusMessage); - addStringHeader(response, "Server", "jdmfws"); - addStringHeader(response, "Transfer-Encoding", "chunked"); + setDefaultJSONRESTHeaders(response); writeHeader(response); jsonStart(out); diff --git a/h/dataservice.h b/h/dataservice.h index e2c35584b..1054c738e 100644 --- a/h/dataservice.h +++ b/h/dataservice.h @@ -83,6 +83,8 @@ void initalizeWebPlugin(WebPlugin *plugin, HttpServer *server); HttpService *makeHttpDataService(DataService *dataService, HttpServer *server); int makeHttpDataServiceUrlMask(DataService *dataService, char *urlMaskBuffer, int urlMaskBufferSize, char *productPrefix); + + #endif /* __DATASERVICE__ */ diff --git a/h/httpserver.h b/h/httpserver.h index dcf56fb81..50cf10f62 100644 --- a/h/httpserver.h +++ b/h/httpserver.h @@ -524,7 +524,10 @@ int streamTextForFile(Socket *socket, UnixFile *in, int encoding, int makeHTMLForDirectory(HttpResponse *response, char *dirname, char *stem, int includeDotted); int makeJSONForDirectory(HttpResponse *response, char *dirname, int includeDotted); - +/** + Convenience function to set headers specific to sending small JSON objects for a REST API + */ +void setDefaultJSONRESTHeaders(HttpResponse *response); int setHttpParseTrace(int toWhat); int setHttpDispatchTrace(int toWhat);