redirect on empty path, small formatting changes, version bump

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 3 years ago
parent b2ed836f63
commit 3e182207e0

@ -14,7 +14,7 @@ import (
const (
// Version holds the current version string
Version = "v3.1.8-beta10"
Version = "v3.1.8-beta11"
)
var (
@ -97,7 +97,7 @@ var (
// Start begins operation of the server
func Start(serve func(*Client)) {
// Start the FileSystemObject cache freshness monitor
// Start the FileCache freshness monitor
SystemLog.Infof(cacheMonitorStartStr, monitorSleepTime)
go FileCache.StartMonitor(monitorSleepTime)

@ -60,6 +60,9 @@ func Run() {
appendCgiEnv,
)
// Generate the root redirect byte slice
rootRedirect = buildRedirect("gemini://" + core.Hostname + ":" + core.Port + "/")
// Start!
core.Start(serve)
}

@ -8,6 +8,10 @@ import (
"github.com/grufwub/go-errors"
)
// rootRedirectHeader stores the root redirect header byte slice,
// because there is no need in recalculating it every time it's needed
var rootRedirect []byte
// serve is the global gemini server's serve function
func serve(client *core.Client) {
// Receive line from client
@ -19,13 +23,6 @@ func serve(client *core.Client) {
}
raw := string(received)
// We don't accept empty requests
if len(raw) == 0 {
client.LogError(invalidRequestStr, raw)
handleError(client, core.ErrInvalidRequest)
return
}
// Ensure is a valid URL string
if core.HasAsciiControlBytes(raw) {
client.LogError(invalidRequestStr, raw)
@ -77,13 +74,18 @@ func serve(client *core.Client) {
return
}
// Redirect empty path to root
if len(path) < 1 {
client.LogInfo(clientRedirectStr, "/")
client.Conn().Write(rootRedirect)
return
}
// Build new Request from raw path and query
request := core.NewRequest(core.BuildPath(path), query)
// Handle the request!
// Handle the request! And finally, error
err = core.HandleClient(client, request)
// Final error handling
if err != nil {
handleError(client, err)
client.LogError(clientServeFailStr, request.String())

@ -35,4 +35,5 @@ const (
invalidRequestStr = "Invalid request: %s"
clientServeFailStr = "Failed to serve: %s"
clientServedStr = "Served: %s"
clientRedirectStr = "Redirect to: %s"
)

Loading…
Cancel
Save