aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2023-02-08 16:03:23 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2023-02-08 16:03:23 -0500
commit10547ba1064ca5a1dd04e782b0df99a22b60de3f (patch)
tree5368ce2ab9133e0ea1c2f12696dd8043f639e742 /captain
parentcf13b8b542cd6eb3c0cf73a2428a7a825dc6252e (diff)
downloadlevitating-10547ba1064ca5a1dd04e782b0df99a22b60de3f.tar.gz
levitating-10547ba1064ca5a1dd04e782b0df99a22b60de3f.zip
Fixed Gemini redirects to keep the session token intact. Might break logging off...
Diffstat (limited to 'captain')
-rw-r--r--captain/gemini.f906
-rw-r--r--captain/response.f9024
2 files changed, 24 insertions, 6 deletions
diff --git a/captain/gemini.f90 b/captain/gemini.f90
index b14078d..cb829e8 100644
--- a/captain/gemini.f90
+++ b/captain/gemini.f90
@@ -237,6 +237,8 @@ contains
character(1024)::text_request
character(UUID_LENGTH+8)::first
+
+ character(len=:), pointer::gemlink
integer::rendered_unit, ioerror
@@ -350,6 +352,10 @@ contains
call write_input_request(ssl, resp%message, code=resp%code)
case(GEMINI_CODE_REDIRECT)
+ if(req%is_authenticated_user()) then
+ gemlink => gemini_session_link_url(resp%url, req%token)
+ call resp%set_url(gemlink)
+ end if
call write_redirect(ssl, resp%url)
case(GEMINI_CODE_PERMFAIL)
diff --git a/captain/response.f90 b/captain/response.f90
index 49f735e..6d9bf46 100644
--- a/captain/response.f90
+++ b/captain/response.f90
@@ -161,8 +161,13 @@ contains
if(link(1:1) == "/") then
if(present(session_token)) then
if(associated(session_token)) then
- nl = nl + 9 + len_trim(session_token)
- prepend_session = .true.
+
+ ! Make sure the url doesn't already have a session token...
+ if(index(link, "/session-"//trim(session_token)) /= 1) then
+ nl = nl + 9 + len_trim(session_token)
+ prepend_session = .true.
+ end if
+
end if
end if
end if
@@ -736,11 +741,18 @@ contains
implicit none
class(response)::resp
- character(*), intent(in)::str
+ character(*), intent(in), optional::str
- if(len_trim(str) > 0) then
- allocate(character(len=len_trim(str)) :: resp%url)
- resp%url = trim(str)
+ if(associated(resp%url)) then
+ deallocate(resp%url)
+ resp%url => null()
+ end if
+
+ if(present(str)) then
+ if(len_trim(str) > 0) then
+ allocate(character(len=len_trim(str)) :: resp%url)
+ resp%url = trim(str)
+ end if
end if
end subroutine response_set_url