aboutsummaryrefslogtreecommitdiff
path: root/captain/web.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-05-06 10:17:03 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-05-06 10:17:03 -0400
commit8ca6d21882c521fb78f1325e9a88a558364b3ad4 (patch)
treec11030395ad1643f436213d0e6d511d2fd0a1131 /captain/web.f90
parent58575b7eb5bbce3b253d55f122ab4f401d49eeba (diff)
downloadlevitating-8ca6d21882c521fb78f1325e9a88a558364b3ad4.tar.gz
levitating-8ca6d21882c521fb78f1325e9a88a558364b3ad4.zip
CGI interface at least starts properly. Fixed rendering of templates to actually take place in CGI mode.
Diffstat (limited to 'captain/web.f90')
-rw-r--r--captain/web.f9032
1 files changed, 29 insertions, 3 deletions
diff --git a/captain/web.f90 b/captain/web.f90
index a0e7a90..ec91d88 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -163,6 +163,7 @@ contains
use config, only: template_filepath, project
use logging
use server_response, only:request, response
+ use http, only: HTTP_CODE_SUCCESS, HTTP_CODE_NOTFOUND
implicit none
type(request), intent(in)::req
@@ -177,9 +178,12 @@ contains
call template_filepath("index.html", template_file)
call page%init(trim(template_file))
+ ! Initialize with success
+ resp%code = HTTP_CODE_SUCCESS
+
call req%path_component(1, first)
- if(trim(req%location) == "/" .or. trim(req%location) == "/index.html") then
+ if(trim(req%location) == "/" .or. trim(req%location) == "/index.html" .or. trim(req%location) == "/home.html") then
call page%assign('title', 'Home')
@@ -229,11 +233,20 @@ contains
else
call page%assign('title', 'Not Found')
-
+ resp%code = HTTP_CODE_NOTFOUND
+
end if
call page%assign('project', project)
+ call page%assign('base_url', req%server)
+ call write_log("Rendering page for "//req%location)
+ call page%render()
+
+ call write_log("Finalizing response", LOG_INFO)
+ resp%temporary_file = .true.
+ resp%body_filename => page%output_filename
+ resp%body_mimetype = "text/html"
end function request_templated
@@ -250,6 +263,8 @@ contains
type(response)::resp
integer::response_size
+ character(64)::logresponse
+
call build_request_object(req)
if(is_request_static(req)) then
@@ -263,6 +278,11 @@ contains
end if
! Perform the response
+ call write_log("Publishing response", LOG_INFO)
+
+ write(logresponse, *) "Response code is: ", resp%code
+ call write_log(trim(logresponse), LOG_INFO)
+
select case(resp%code)
case(HTTP_CODE_REDIRECT)
call write_redirect(output_unit, resp%code, trim(resp%url))
@@ -272,13 +292,19 @@ contains
call write_response_headers(output_unit, resp%code, response_size, trim(resp%body_mimetype))
call echo_file_stdout(resp%body_filename)
+ case(HTTP_CODE_FAILURE)
+ call write_log("Failure reported for location: "//trim(req%location), LOG_NORMAL)
! Need some more...
end select
-
+
+ call write_log("Cleanup", LOG_INFO)
+
call resp%destroy()
call req%destroy()
+ call write_log("Exit handler", LOG_INFO)
+
end subroutine handle_request
end module web