diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-05-12 09:19:59 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-05-12 09:19:59 -0400 |
commit | 738833d70c8d6cca3bbf9efe0c8dd24ed0395dde (patch) | |
tree | 2b7a565b3a9753f9aa78defcbe2ba57805d51ee7 /captain/postutils.f90 | |
parent | a213818a689e41df697d1b2baf6864fc62859fdb (diff) | |
download | levitating-738833d70c8d6cca3bbf9efe0c8dd24ed0395dde.tar.gz levitating-738833d70c8d6cca3bbf9efe0c8dd24ed0395dde.zip |
Added post handling to the captain. Improved the query utilities for extracting values from a query string. Added a redirect template for html.
Diffstat (limited to 'captain/postutils.f90')
-rw-r--r-- | captain/postutils.f90 | 45 |
1 files changed, 45 insertions, 0 deletions
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 |