From 738833d70c8d6cca3bbf9efe0c8dd24ed0395dde Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 12 May 2021 09:19:59 -0400 Subject: Added post handling to the captain. Improved the query utilities for extracting values from a query string. Added a redirect template for html. --- captain/postutils.f90 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 captain/postutils.f90 (limited to 'captain/postutils.f90') diff --git a/captain/postutils.f90 b/captain/postutils.f90 new file mode 100644 index 0000000..c5af8bd --- /dev/null +++ b/captain/postutils.f90 @@ -0,0 +1,45 @@ +module http_post_utilities +implicit none + + character(*), parameter::content_type_required = "application/x-www-form-urlencoded" + +contains + + function read_post_contents() result(res) + use query_utilities, only: query + implicit none + + type(query)::res + + character(len=:), allocatable::transfered + character(256)::header_info + integer::content_length, istat, i + + call get_environment_variable("CONTENT_LENGTH", header_info, status=istat) + if(istat == 0) then + read(header_info, '(I8)') content_length + else + content_length = 0 + end if + + call get_environment_variable("CONTENT_TYPE", header_info, status=istat) + if(content_length > 0 .and. & + istat == 0 .and. & + trim(header_info) /= content_type_required) & + then + + allocate(character(len=content_length) :: transfered) + + do i = 1, content_length + read(*, '(A1)', advance='no') transfered(i:i) + end do + + call res%init(transfered) + + deallocate(transfered) + + end if + + end function read_post_contents + +end module http_post_utilities \ No newline at end of file -- cgit v1.2.3