[Refactor] web server header cleanups (#16)

* Rename variables

* Content type headers

* Headers cleanup
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2022-11-29 18:43:23 -05:00
1 parent 27b4ad90d3
commit 1734425b9c
4 files changed
+72 -62

No files matched your search

@@ -41,13 +41,14 @@ namespace Http
response.Default(403, "Forbidden")
return false
end if
response.mimetype = "text/html"
response.ContentType("text/html")
router.GenerateDirectoryListing(path, router, request, response)
return true
else if stat.type = "file"
response.mimetype = WebUtils.MimeType(decoded_path)
mimetype = WebUtils.MimeType(decoded_path)
response.ContentType(mimetype)
response.fileLength = stat.size
router.log.info("uri=" + request.uri + ", target=" + path + ", content-type=" + response.mimetype + ", content-length=" + Stri(response.fileLength).trim())
router.log.info("uri=" + request.uri + ", target=" + path + ", content-type=" + mimetype + ", content-length=" + Stri(response.fileLength).trim())
router.GenerateFile(path, router, request, response)
return true
else
@@ -90,15 +91,19 @@ namespace Http
end if
response.start = start
response.length = finish - start + 1
response.body_buffer_length = finish - start + 1
response.ContentLength(response.body_buffer_length)
response.headers["Content-Range"] = "bytes " + response.MakeRange(response.start, response.body_buffer_length, response.filelength)
response.http_code = 206
router.log.info("sending range " + response.MakeRange(start, response.length, response.fileLength))
router.log.info("sending range " + response.MakeRange(start, response.body_buffer_length, response.fileLength))
else ' no range stuff
response.length = response.fileLength
response.body_buffer_length = response.fileLength
response.ContentLength(response.body_buffer_length)
response.http_code = 200
end if
response.headers["Accept-Ranges"] = "bytes"
response.GenerateHeader()
return true
end function
@@ -166,9 +171,7 @@ namespace Http
listing = listing + "</body>" + UnixNL()
listing = listing + "</html>" + UnixNL()
response.buf.FromAsciiString(listing)
response.length = response.buf.count()
response.SetBodyDataString(listing)
response.http_code = 200
response.GenerateHeader()
response.source = Http.HttpResponseSource.GENERATED