mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Move to go-modrinth lib (v2 API) and always supply UA in HTTP requests
This commit is contained in:
@@ -13,6 +13,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const UserAgent = "packwiz/packwiz"
|
||||
|
||||
func GetWithUA(url string, contentType string) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
req.Header.Set("Accept", contentType)
|
||||
return http.DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
const DownloadCacheImportFolder = "import"
|
||||
|
||||
type DownloadSession interface {
|
||||
@@ -143,8 +155,7 @@ func downloadNewFile(task *downloadTask, cacheFolder string, hashesToObtain []st
|
||||
if len(hashesToObtain) > 0 {
|
||||
var data io.ReadCloser
|
||||
if task.url != "" {
|
||||
resp, err := http.Get(task.url)
|
||||
// TODO: content type, user-agent?
|
||||
resp, err := GetWithUA(task.url, "application/octet-stream")
|
||||
if err != nil {
|
||||
return CompletedDownload{}, fmt.Errorf("failed to download %s: %w", task.url, err)
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package core
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -53,7 +52,7 @@ var ModLoaders = map[string]ModLoaderComponent{
|
||||
|
||||
func FetchMavenVersionList(url string) func(mcVersion string) ([]string, string, error) {
|
||||
return func(mcVersion string) ([]string, string, error) {
|
||||
res, err := http.Get(url)
|
||||
res, err := GetWithUA(url, "application/xml")
|
||||
if err != nil {
|
||||
return []string{}, "", err
|
||||
}
|
||||
@@ -69,7 +68,7 @@ func FetchMavenVersionList(url string) func(mcVersion string) ([]string, string,
|
||||
|
||||
func FetchMavenVersionPrefixedList(url string, friendlyName string) func(mcVersion string) ([]string, string, error) {
|
||||
return func(mcVersion string) ([]string, string, error) {
|
||||
res, err := http.Get(url)
|
||||
res, err := GetWithUA(url, "application/xml")
|
||||
if err != nil {
|
||||
return []string{}, "", err
|
||||
}
|
||||
|
Reference in New Issue
Block a user