Skip to content

Commit

Permalink
Merge pull request #165 from 1000TurquoisePogs/bugfix/dotfile-and-for…
Browse files Browse the repository at this point in the history
…ced-encoding

Fix for untagged and dotfiles not being properly sent over rest api
  • Loading branch information
1000TurquoisePogs authored Sep 3, 2020
2 parents ff10b59 + f572f82 commit ef72720
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Zowe Common C Changelog

## `1.16.0`

- Fixed mimetype lookup for dotfiles

## `1.13.0`

- Initialized http server log earlier, a bugfix to show error messages that were hidden before.
30 changes: 24 additions & 6 deletions c/httpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3689,11 +3689,10 @@ HttpRequestParam *getCheckedParam(HttpRequest *request, char *paramName){
static char *getMimeType2(char *extension, int *isBinary, int dotPos);

char *getMimeType(char *extension, int *isBinary) {
int dotPos = -1;
getMimeType2(extension, isBinary, dotPos);
getMimeType2(extension, isBinary, FALSE);
}

static char *getMimeType2(char *extension, int *isBinary, int dotPos){
static char *getMimeType2(char *extension, int *isBinary, int isDotFile){
if (!strcmp(extension,"js")){
*isBinary = FALSE;
return "text/javascript";
Expand All @@ -3705,7 +3704,7 @@ static char *getMimeType2(char *extension, int *isBinary, int dotPos){
!strcmp(extension,"cbl") || !strcmp(extension,"cpy") || !strcmp(extension,"asm") ||
!strcmp(extension,"cpp") || !strcmp(extension,"h") || !strcmp(extension,"log") ||
!strcmp(extension,"env") ||
(dotPos == 0)){
(isDotFile == TRUE)){
*isBinary = FALSE;
return "text/plain";
} else if (!strcmp(extension,"html") ||
Expand Down Expand Up @@ -3982,12 +3981,22 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab

if(status == 0) {
int filenameLen = strlen(absolutePath);
#ifdef DEBUG
printf("Request for file=%s\n",absolutePath);
#endif
int dotPos = lastIndexOf(absolutePath, filenameLen, '.');
int isDotFile = FALSE;
if (dotPos > 0 && (absolutePath[dotPos-1] == '/')){
isDotFile = TRUE;
}
char *extension = (dotPos == -1) ? "NULL" : absolutePath + dotPos + 1;
int isBinary = FALSE;
char *mimeType = getMimeType2(extension,&isBinary,dotPos);
char *mimeType = getMimeType2(extension,&isBinary,isDotFile);
long fileSize = fileInfoSize(&info);
int ccsid = fileInfoCCSID(&info);
#ifdef DEBUG
printf("File ccsid=%d, mimetype=%s\n",ccsid,mimeType);
#endif
char tmperr[256] = {0};
#if defined(__ZOWE_OS_AIX) || defined(__ZOWE_OS_LINUX)
time_t mtime = info.st_mtime;
Expand Down Expand Up @@ -4084,7 +4093,7 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab
#endif
;
char *forceEnabled = getQueryParam(response->request, "force");
if (ccsid == 0 && strcmp(forceEnabled, "enable")) {
if (ccsid == 0 && !strcmp(forceEnabled, "enable")) {
char *sourceEncoding = getQueryParam(response->request, "source");
char *targetEncoding = getQueryParam(response->request, "target");
int sEncoding;
Expand All @@ -4096,6 +4105,9 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab
respondWithError(response, HTTP_STATUS_BAD_REQUEST, "source/target encoding value parsing error.");
return;
}
#ifdef DEBUG
printf("Sending with forced conversion between %d and %d\n");
#endif
streamTextForFile2(response, NULL, in, ENCODING_CHUNKED, sEncoding, tEncoding, asB64);
}
else {
Expand All @@ -4104,9 +4116,15 @@ void respondWithUnixFile2(HttpService* service, HttpResponse* response, char* ab
}
}
else if(ccsid == 0) {
#ifdef DEBUG
printf("Sending with default conversion between %d and %d\n", NATIVE_CODEPAGE, webCodePage);
#endif
streamTextForFile2(response, NULL, in, ENCODING_CHUNKED, NATIVE_CODEPAGE, webCodePage, asB64);
}
else {
#ifdef DEBUG
printf("Sending with tagged conversion between %d and %d\n", ccsid, webCodePage);
#endif
streamTextForFile2(response, NULL, in, ENCODING_CHUNKED, ccsid, webCodePage, asB64);
}

Expand Down

0 comments on commit ef72720

Please sign in to comment.