mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-27 16:38:14 +01:00
Fix link parsing
This commit is contained in:
parent
26115183a9
commit
9cf58a9982
2 changed files with 22 additions and 13 deletions
|
@ -68,21 +68,30 @@ func Convert(page []byte, u string) []byte {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if l >= 7 && bytes.HasPrefix(line, []byte("=> ")) {
|
if l >= 6 && bytes.HasPrefix(line, []byte("=>")) {
|
||||||
split := bytes.SplitN(line[3:], []byte(" "), 2)
|
splitStart := 2
|
||||||
if len(split) != 2 {
|
if line[splitStart+1] == ' ' || line[splitStart+1] == '\t' {
|
||||||
split = bytes.SplitN(line[3:], []byte("\t"), 2)
|
splitStart++
|
||||||
}
|
}
|
||||||
|
split := bytes.SplitN(line[splitStart:], []byte(" "), 2)
|
||||||
|
if len(split) != 2 {
|
||||||
|
split = bytes.SplitN(line[splitStart:], []byte("\t"), 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
linkURL := line[splitStart:]
|
||||||
|
linkLabel := line[splitStart:]
|
||||||
if len(split) == 2 {
|
if len(split) == 2 {
|
||||||
link := append([]byte(`<a href="`), rewriteURL(string(split[0]), parsedURL)...)
|
linkURL = split[0]
|
||||||
|
linkLabel = split[1]
|
||||||
|
}
|
||||||
|
link := append([]byte(`<a href="`), rewriteURL(string(linkURL), parsedURL)...)
|
||||||
link = append(link, []byte(`">`)...)
|
link = append(link, []byte(`">`)...)
|
||||||
link = append(link, split[1]...)
|
link = append(link, linkLabel...)
|
||||||
link = append(link, []byte(`</a>`)...)
|
link = append(link, []byte(`</a>`)...)
|
||||||
result = append(result, link...)
|
result = append(result, link...)
|
||||||
result = append(result, []byte("<br>")...)
|
result = append(result, []byte("<br>")...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
heading := 0
|
heading := 0
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
|
|
|
@ -114,7 +114,7 @@ func fetch(u string) ([]byte, []byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.HasPrefix(header, []byte("2")) {
|
if !bytes.HasPrefix(header, []byte("2")) {
|
||||||
return header, []byte(fmt.Sprintf("Unexpected header: %s", header)), nil
|
return header, []byte(fmt.Sprintf(pageHeader+"Server sent unexpected header:<br><br><b>%s</b>", header) + pageFooter), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.HasPrefix(header, []byte("20 text/html")) {
|
if bytes.HasPrefix(header, []byte("20 text/html")) {
|
||||||
|
@ -223,13 +223,13 @@ func LastRequestTime() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetClientCertificate sets the client certificate to use for a domain.
|
// SetClientCertificate sets the client certificate to use for a domain.
|
||||||
func SetClientCertificate(domain string, certificate string, privateKey string) error {
|
func SetClientCertificate(domain string, certificate []byte, privateKey []byte) error {
|
||||||
if len(certificate) == 0 || len(privateKey) == 0 {
|
if len(certificate) == 0 || len(privateKey) == 0 {
|
||||||
delete(clientCerts, domain)
|
delete(clientCerts, domain)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
clientCert, err := tls.LoadX509KeyPair(certificate, privateKey)
|
clientCert, err := tls.X509KeyPair(certificate, privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrInvalidCertificate
|
return ErrInvalidCertificate
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue