Skip to content

Commit a46f0eb

Browse files
authored
Merge pull request #27 from SwimResults/develop
allow downloading pdf files from external hosts by using User-Agent H…
2 parents 6af8b19 + 485b6d3 commit a46f0eb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

importer/dsv_importer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ func getFileReader(file string) (io.Reader, error) {
2222

2323
if strings.Contains(file, "http") {
2424
// get file content from url
25-
resp, err := http.Get(file)
25+
req, err := http.NewRequest("GET", file, nil)
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT x.y; rv:10.0) Gecko/20100101 Firefox/10.0")
31+
client := &http.Client{}
32+
resp, err := client.Do(req)
2633
if err != nil {
2734
return nil, err
2835
}

importer/pdf_importer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ func TestGetPdfFileContent(t *testing.T) {
1212
assert.Equal(t, "erzeugt mit \"EasyWk vom 16.05.2022\" - www.easywk.de25. Internationaler Erzgebirgs-Schwimmcup 2022Seite 1www.sv-zwickau04.deWettkampf 47 - 200m Schmetterling weiblichLauf 1 (ca. 15:01 Uhr)BahnSchwimmerinJg.VereinMeldezeitBahn 2 Kreißig, Lilly 2006 SV 1990 Zschopau 03:04,40Bahn 3 Epperlein, Linda 2008 SV Zwickau von 1904 03:18,54Lauf 2 (ca. 15:04 Uhr)BahnSchwimmerinJg.VereinMeldezeitBahn 1 Maraskova, Linda 2009 Plavecký klub Litvínov 03:02,55Bahn 2 Kunz, Jenny 2007 SV Zwickau von 1904 02:50,99Bahn 3 Richter, Nele 2002 ST Erzgebirge 02:57,21", text)
1313
}
1414

15+
func TestGetPdfFileContent_External(t *testing.T) {
16+
text, _ := GetPdfFileContent("https://bsv-sws.de/images/dateien/2025/BML/BM_lang_2025.pdf")
17+
println(text)
18+
assert.Contains(t, text, "Offene Bezirksjahrgangs- und Bezirksmeisterschaften 2025 - lange Strecken")
19+
}
20+
1521
func TestImportPdfStartList_BMSWS24(t *testing.T) {
1622
settings := model.ImportPdfStartListSettings{
1723
OmitFirst: nil,

0 commit comments

Comments
 (0)