diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-05-04 16:44:20 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-05-04 16:44:20 -0400 |
commit | 877b8876b078c8ab2632c17ab09e0ac0c2789c8a (patch) | |
tree | ba63e85cdaaef78aedc006854125312ff6607b21 /captain/response.f90 | |
parent | e789ce4a4bc1f0894a707d2a141bbf357e0ba2d5 (diff) | |
download | levitating-877b8876b078c8ab2632c17ab09e0ac0c2789c8a.tar.gz levitating-877b8876b078c8ab2632c17ab09e0ac0c2789c8a.zip |
Initial work on the CGI interface for web access.
Diffstat (limited to 'captain/response.f90')
-rw-r--r-- | captain/response.f90 | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/captain/response.f90 b/captain/response.f90 index 09299fc..1fc21b1 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -92,12 +92,13 @@ implicit none contains - subroutine request_init(self, str) + subroutine request_init(self, str, server_explicit, protocol_explicit) use logging implicit none class(request) :: self character(*), intent(in)::str + character(*), intent(in), optional::server_explicit, protocol_explicit integer::i, j, n @@ -107,17 +108,41 @@ contains call write_log("URL: "//self%url, LOG_NORMAL) i = index(str, "://") - allocate(character(len=(i-1)) :: self%protocol) - self%protocol = str(1:i-1) + if(i <= 0 .and. present(protocol_explicit)) then + allocate(character(len=len_trim(protocol_explicit)) :: self%protocol) + self%protocol = protocol_explicit + i = 1 + else + allocate(character(len=(i-1)) :: self%protocol) + self%protocol = str(1:i-1) + i = i + 3 + end if call write_log("Protocol: "//self%protocol, LOG_DEBUG) - i = i + 3 - j = index(str(i:n), "/") - if(j <= 0) then - j = len_trim(str) + 1 - i + ! We only want to "assume" the server if a :// was never found + if(i == 1 .and. present(server_explicit)) then + allocate(character(len=len_trim(server_explicit)) :: self%server) + self%server = server_explicit + + ! This string, in CGI cases, actually represents the SCRIPT root, + ! so we need to skip ahead of it in the URL if it is there... + i = index(str, self%server) + if(i > 0) then + i = i + len(self%server) + else + i = 1 + end if + + else + + j = index(str(i:n), "/") + if(j <= 0) then + j = len_trim(str) + 1 - i + end if + allocate(character(len=(j-1)) :: self%server) + self%server = str(i:(i+j-1)) + end if - allocate(character(len=(j-1)) :: self%server) - self%server = str(i:(i+j-1)) call write_log("Server: "//self%server//"|", LOG_DEBUG) i = j+i-1 |