aboutsummaryrefslogtreecommitdiff
path: root/protocol.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-05-06 17:42:40 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-05-06 17:42:40 -0400
commit09a2a56e22ce36238dce94f927f1909b63493960 (patch)
tree2a1f9c7c5287553bf29b67d86661eaede5783eb5 /protocol.f90
parent9c957c4a0964ee1f5b0ff582543b9f526978c47e (diff)
downloadLR-87-09a2a56e22ce36238dce94f927f1909b63493960.zip
LR-87-09a2a56e22ce36238dce94f927f1909b63493960.tar.gz
File type is now returned for evaluation. Initial routines for saving implemented but unused.
Diffstat (limited to 'protocol.f90')
-rw-r--r--protocol.f9044
1 files changed, 42 insertions, 2 deletions
diff --git a/protocol.f90 b/protocol.f90
index 76fb8d4..194e0e7 100644
--- a/protocol.f90
+++ b/protocol.f90
@@ -14,7 +14,44 @@ implicit none
contains
- function request_url(url, unit_number, server_name) result(returncode)
+ subroutine read_mimetype(unit_number, return_type)
+ implicit none
+ integer, intent(in)::unit_number
+ character(*), intent(out)::return_type
+
+ character::c
+ integer::iostatus, i
+
+ return_type = " "
+
+ ! Advance past status and space
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ do while(c /= " " .and. c /= char(9) .and. iostatus == 0)
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+ do while((c == " " .or. c == char(9)) .and. iostatus == 0)
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+
+ if(iostatus == 0) then
+ ! c now contains the first entry of the mimetype
+ i = 0
+ do while(iostatus == 0)
+ i = i + 1
+ return_type(i:i) = c
+ read(unit_number, '(A1)', advance='no', iostat=iostatus) c
+ end do
+
+ end if
+
+ ! Default
+ if(len_trim(return_type) == 0) then
+ return_type = "text/gemini"
+ end if
+
+ end subroutine read_mimetype
+
+ function request_url(url, unit_number, return_type, server_name) result(returncode)
use request
use iso_c_binding
use file_handling, only: mark_file_end
@@ -22,6 +59,7 @@ contains
character(*), intent(inout)::url
integer, intent(in)::unit_number
+ character(*), intent(out)::return_type
character(*), intent(in), optional::server_name
integer::returncode
@@ -64,9 +102,11 @@ contains
call mark_file_end(unit_number)
rewind(unit_number)
- read(unit_number, '(I1)', iostat=iostatus) returncode
+ read(unit_number, '(I1)', iostat=iostatus, advance='no') returncode
if(iostatus /= 0) then
returncode = STATUS_BADRESPONSE
+ else
+ call read_mimetype(unit_number, return_type)
end if
else