diff options
Diffstat (limited to 'captain/response.f90')
-rw-r--r-- | captain/response.f90 | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/captain/response.f90 b/captain/response.f90 index e1d80eb..2f48caa 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -24,6 +24,8 @@ module server_response procedure :: destroy => response_destroy procedure :: set_message => response_set_message procedure :: set_url => response_set_url + procedure :: set_body_contents => response_temp_file_contents + procedure :: set_filename => response_set_filename_using_allocation end type @@ -255,4 +257,47 @@ contains end subroutine response_set_url + subroutine response_temp_file_contents(resp, str, mimetype) + use utilities, only: generate_temporary_filename + implicit none + + class(response)::resp + character(*), intent(in)::str + character(*), intent(in), optional::mimetype + + integer::unum + + resp%body_filename => generate_temporary_filename() + open(newunit=unum, file=resp%body_filename, action="write", status="new") + write(unum, *) str + close(unum) + + resp%temporary_file = .true. + + if(present(mimetype)) then + resp%body_mimetype = mimetype + else + resp%body_mimetype = "text/plain" + end if + + end subroutine response_temp_file_contents + + subroutine response_set_filename_using_allocation(resp, fname, mimetype) + implicit none + + class(response)::resp + character(*), intent(in)::fname + character(*), intent(in), optional::mimetype + + allocate(character(len=len_trim(fname)) :: resp%body_filename) + resp%body_filename = trim(fname) + + if(present(mimetype)) then + resp%body_mimetype = mimetype + else + resp%body_mimetype = "text/plain" + end if + + end subroutine response_set_filename_using_allocation + end module server_response |