mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-16 12:57:58 +08:00
31 lines
661 B
Go
31 lines
661 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", userAgent)
|
|
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
|
|
}
|