Support XML and Atom responses
This commit is contained in:
parent
5cedea4836
commit
f3333ab888
14
main.go
14
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -19,6 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const TIMEOUT_NS time.Duration = time.Duration(60_000_000_000)
|
const TIMEOUT_NS time.Duration = time.Duration(60_000_000_000)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hosts tofu.KnownHosts
|
hosts tofu.KnownHosts
|
||||||
hostsfile *tofu.HostWriter
|
hostsfile *tofu.HostWriter
|
||||||
|
@ -158,9 +160,14 @@ func main() {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.Meta != "text/gemini" && !strings.HasPrefix(resp.Meta, "text/gemini;") {
|
mime, _, _ := strings.Cut(resp.Meta, ";")
|
||||||
log.Fatal("mime type is not text/gemini")
|
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{
|
aw := AtomWriter{
|
||||||
Title: "",
|
Title: "",
|
||||||
Items: nil,
|
Items: nil,
|
||||||
|
@ -206,4 +213,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Println(string(out))
|
fmt.Println(string(out))
|
||||||
|
} else {
|
||||||
|
log.Fatal("unsupported mime type: ", mime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue