~elektito/hodhod

13087d009bb176912e73ef030917533053fdbc74 — Mostafa Razavi 1 year, 3 months ago d21b968
Rename the project to Hodhod
10 files changed, 26 insertions(+), 26 deletions(-)

M Makefile
M README.md
M go.mod
M main.go
R pkg/{gemplex/cgi.go => hodhod/cgi.go}
R pkg/{gemplex/config.go => hodhod/config.go}
R pkg/{gemplex/error_resp.go => hodhod/error_resp.go}
R pkg/{gemplex/request.go => hodhod/request.go}
R pkg/{gemplex/response.go => hodhod/response.go}
R pkg/{gemplex/static.go => hodhod/static.go}
M Makefile => Makefile +1 -1
@@ 1,4 1,4 @@
NAME=gemplex
NAME=hodhod
BINDIR ?= .
SRC != find . -name '*.go' ! -name '*_test.go'


M README.md => README.md +9 -9
@@ 1,14 1,14 @@
# About Gemplex
# About Hodhod

Gemplex is a Gemini server, capable of serving multiple capsules. Apart from
Hodhod is a Gemini server, capable of serving multiple capsules. Apart from
static content, it also supports serving dynamic content through CGI scripts.

Gemplex is still far from being battle-tested and feature complete. Check the
Hodhod is still far from being battle-tested and feature complete. Check the
"Completion Status" section to find out more.

# Completion Status

The following features are planned for Gemplex.
The following features are planned for Hodhod.

 - [x] Serve static content
 - [x] Serve dynamic content through CGI


@@ 26,15 26,15 @@ And maybe later:
 
# Installation

You can install gemplex by running:
You can install hodhod by running:

``` sh
go install github.com/elektito/gemplex@latest
go install github.com/elektito/hodhod@latest
```

# Config File

Gemplex uses a json formatted configuration file. Here's an example:
Hodhod uses a json formatted configuration file. Here's an example:

``` json
{


@@ 122,7 122,7 @@ following values are allowed for this field:
   URLs that don't have one, before pattern matching.
 - `remove`: The trailing slash, if present, is always removed from the request
   URL before pattern matching.
 - `ifpresent`: Gemplex will not add or remove trailing slashes. The trailing
 - `ifpresent`: Hodhod will not add or remove trailing slashes. The trailing
   slash, if present, will be part of the URL when matching for patterns.

## Backends


@@ 150,7 150,7 @@ For `cgi` backends, the following fields are available:

## Certificates

The `certs` key contains a list of certificates to be used by Gemplex. The
The `certs` key contains a list of certificates to be used by Hodhod. The
appropriate certificate will be chosen and served based on the request SNI
value.


M go.mod => go.mod +1 -1
@@ 1,3 1,3 @@
module github.com/elektito/gemplex
module github.com/elektito/hodhod

go 1.20

M main.go => main.go +8 -8
@@ 15,7 15,7 @@ import (
	"sync"
	"time"

	"github.com/elektito/gemplex/pkg/gemplex"
	"github.com/elektito/hodhod/pkg/hodhod"
)

const (


@@ 48,7 48,7 @@ func fail(whileDoing string, err error) {
	os.Exit(1)
}

func getResponseForRequest(req gemplex.Request, cfg *gemplex.Config) (resp gemplex.Response, err error) {
func getResponseForRequest(req hodhod.Request, cfg *hodhod.Config) (resp hodhod.Response, err error) {
	backend, unmatched := cfg.GetBackendByUrl(req.Url)
	if backend == nil {
		err = errNotFound(req.Url.String(), "no route")


@@ 57,19 57,19 @@ func getResponseForRequest(req gemplex.Request, cfg *gemplex.Config) (resp gempl

	if backend.Type == "static" {
		filename := path.Join(backend.Location, unmatched)
		resp = gemplex.NewFileResp(filename, cfg)
		resp = hodhod.NewFileResp(filename, cfg)
		return
	}

	if backend.Type == "cgi" {
		resp = gemplex.NewCgiResp(req, backend.Script, cfg)
		resp = hodhod.NewCgiResp(req, backend.Script, cfg)
		return
	}

	return
}

func handleConn(conn net.Conn, cfg *gemplex.Config) {
func handleConn(conn net.Conn, cfg *hodhod.Config) {
	defer conn.Close()

	log.Println("Accepted connection.")


@@ 95,7 95,7 @@ func handleConn(conn net.Conn, cfg *gemplex.Config) {
		conn.Write([]byte("59 Bad Request\r\n"))
		return
	}
	req := gemplex.Request{
	req := hodhod.Request{
		Url:        urlParsed,
		RemoteAddr: conn.RemoteAddr().String(),
	}


@@ 144,7 144,7 @@ func handleConn(conn net.Conn, cfg *gemplex.Config) {
	log.Println("Closed connection.")
}

func loadCertificates(cfg *gemplex.Config) (certs []tls.Certificate, err error) {
func loadCertificates(cfg *hodhod.Config) (certs []tls.Certificate, err error) {
	certs = make([]tls.Certificate, len(cfg.Certs))
	for i, c := range cfg.Certs {
		certs[i], err = tls.LoadX509KeyPair(c.CertFile, c.KeyFile)


@@ 171,7 171,7 @@ func main() {
	configFile := flag.String("config", "config.json", "Path to config file")
	flag.Parse()

	cfg, err := gemplex.LoadConfig(*configFile)
	cfg, err := hodhod.LoadConfig(*configFile)
	if err != nil {
		fail("loading config", err)
	}

R pkg/gemplex/cgi.go => pkg/hodhod/cgi.go +2 -2
@@ 1,4 1,4 @@
package gemplex
package hodhod

import (
	"context"


@@ 66,7 66,7 @@ func NewCgiResp(req Request, scriptPath string, cfg *Config) (resp Response) {
		"GATEWAY_INTERFACE=CGI/1.1",
		"SERVER_PROTOCOL=GEMINI",
		"REQUEST_METHOD=",
		"SERVER_SOFTWARE=gemplex",
		"SERVER_SOFTWARE=hodhod",
		fmt.Sprintf("GEMINI_URL=%s", req.Url.String()),
		fmt.Sprintf("GEMINI_URL_PATH=%s", req.Url.Path),
		fmt.Sprintf("PATH_INFO=%s", req.Url.Path),

R pkg/gemplex/config.go => pkg/hodhod/config.go +1 -1
@@ 1,4 1,4 @@
package gemplex
package hodhod

import (
	"encoding/json"

R pkg/gemplex/error_resp.go => pkg/hodhod/error_resp.go +1 -1
@@ 1,4 1,4 @@
package gemplex
package hodhod

import (
	"fmt"

R pkg/gemplex/request.go => pkg/hodhod/request.go +1 -1
@@ 1,4 1,4 @@
package gemplex
package hodhod

import "net/url"


R pkg/gemplex/response.go => pkg/hodhod/response.go +1 -1
@@ 1,4 1,4 @@
package gemplex
package hodhod

import (
	"io"

R pkg/gemplex/static.go => pkg/hodhod/static.go +1 -1
@@ 1,4 1,4 @@
package gemplex
package hodhod

import (
	"fmt"