From 10547ba1064ca5a1dd04e782b0df99a22b60de3f Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 8 Feb 2023 16:03:23 -0500 Subject: Fixed Gemini redirects to keep the session token intact. Might break logging off... --- captain/gemini.f90 | 6 ++++++ captain/response.f90 | 24 ++++++++++++++++++------ 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 -- cgit v1.2.3