diff options
Diffstat (limited to 'captain')
-rw-r--r-- | captain/BUILD.md | 6 | ||||
-rw-r--r-- | captain/api.f90 | 3 | ||||
-rw-r--r-- | captain/requtils.f90 | 29 |
3 files changed, 36 insertions, 2 deletions
diff --git a/captain/BUILD.md b/captain/BUILD.md index 506adc4..d926a4b 100644 --- a/captain/BUILD.md +++ b/captain/BUILD.md @@ -6,17 +6,19 @@ though it should work on any UNIX-y system with a modern Fortran compiler. ## Requirements -The captain only has three dependencies: +The captain only has five dependencies: * SQLite3 development libraries * SSL development libraries * uuidgen + * mimetype + * gzip/gunzip The first two are necessary for building, while the third is a runtime dependency. These can be installed on Debian with the following command: ``` -apt-get install libssl-dev libsqlite3-dev uuid-runtime +apt-get install libssl-dev libsqlite3-dev uuid-runtime gzip libfile-mimeinfo-perl ``` ## Building diff --git a/captain/api.f90 b/captain/api.f90 index fa72b9d..455c3b0 100644 --- a/captain/api.f90 +++ b/captain/api.f90 @@ -256,6 +256,9 @@ contains if(req%write_to(fullpath)) then + ! Compress all these damn results + call execute_command_line('gzip -9 "'//fullpath//'"', wait=.false.) + resp%code = GEMINI_CODE_SUCCESS call resp%set_body_contents(RESPONSE_JSON_OKAY) resp%body_mimetype = "text/plain" diff --git a/captain/requtils.f90 b/captain/requtils.f90 index 03fe869..a993eeb 100644 --- a/captain/requtils.f90 +++ b/captain/requtils.f90 @@ -241,6 +241,29 @@ contains end function is_request_static + subroutine try_static_gzipd_file(resp, exist) + use server_response + implicit none + + type(response), intent(inout)::resp + logical, intent(out)::exist + + character(len=:), pointer::gzfilename + + allocate(character(len=(len_trim(resp%body_filename) + 3)) :: gzfilename) + + gzfilename = trim(resp%body_filename)//".gz" + inquire(file=gzfilename, exist=exist) + if(exist) then + ! Unzip but keep the compressed version + call execute_command_line('gunzip -k "'//gzfilename//'"', wait=.true.) + + ! Mark the file as temporary because we can delete it after transfer + resp%temporary_file = .true. + end if + + end subroutine try_static_gzipd_file + function request_static(req) result(resp) use logging use config @@ -272,8 +295,14 @@ contains resp%body_filename => get_special_full_filename(trim(category), trim(filename)) inquire(file=resp%body_filename, exist=exists) + + ! See if a gzip version is around if(.not. exists) then + call try_static_gzipd_file(resp, exist=exists) + end if + if(.not. exists) then + resp%code = notfound_code(req) call write_log("File did not exist: "//resp%body_filename, LOG_NORMAL) |