shiori/internal/core/download.go
2019-09-20 16:48:57 +07:00

31 lines
705 B
Go

package core
import (
"io"
"net/http"
"time"
)
var httpClient = &http.Client{Timeout: time.Minute}
// DownloadBookmark downloads bookmarked page from specified URL.
// Return response body, make sure to close it later.
func DownloadBookmark(url string) (io.ReadCloser, string, error) {
// Prepare download request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, "", err
}
// Send download request
req.Header.Set("User-Agent", "Shiori/2.0.0 (+https://github.com/go-shiori/shiori)")
resp, err := httpClient.Do(req)
if err != nil {
return nil, "", err
}
// Get content type
contentType := resp.Header.Get("Content-Type")
return resp.Body, contentType, nil
}