Support XML and Atom responses

This commit is contained in:
blankie 2022-07-19 20:48:50 +07:00
parent 5cedea4836
commit f3333ab888
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 53 additions and 43 deletions

14
main.go
View File

@ -6,6 +6,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"io"
"log"
"net/url"
"os"
@ -19,6 +20,7 @@ import (
)
const TIMEOUT_NS time.Duration = time.Duration(60_000_000_000)
var (
hosts tofu.KnownHosts
hostsfile *tofu.HostWriter
@ -158,9 +160,14 @@ func main() {
}
defer resp.Body.Close()
if resp.Meta != "text/gemini" && !strings.HasPrefix(resp.Meta, "text/gemini;") {
log.Fatal("mime type is not text/gemini")
mime, _, _ := strings.Cut(resp.Meta, ";")
if mime == "application/rss+xml" || mime == "application/atom+xml" {
out, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Print(string(out))
} else if mime == "text/gemini" {
aw := AtomWriter{
Title: "",
Items: nil,
@ -206,4 +213,7 @@ func main() {
log.Fatal(err)
}
fmt.Println(string(out))
} else {
log.Fatal("unsupported mime type: ", mime)
}
}