Skip to content

Commit

Permalink
est: more robust client file handling
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ott <[email protected]>
  • Loading branch information
smo4201 committed Sep 17, 2024
1 parent 2b6190a commit 75260c9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion est/estclient/fileserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,20 @@ func FetchMetadata(addr string) ([][]byte, error) {
return nil, fmt.Errorf("failed to read HTTP response body: %w", err)
}

// Extract relevant content, avoiding xml errors of irrelevant sections
scontent := string(content)
startTag := "<pre>"
endTag := "</pre>"
startIdx := strings.Index(scontent, startTag)
endIdx := (strings.Index(scontent, endTag))
if startIdx == -1 || endIdx == -1 {
return nil, fmt.Errorf("failed to extract xml from content: %v", scontent)
}
extracted := []byte(scontent[startIdx : endIdx+len(endTag)])

// Parse root directory
var pre Pre
err = xml.Unmarshal(content, &pre)
err = xml.Unmarshal(extracted, &pre)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal HTTP response: %w. Response: %v",
err, string(content))
Expand Down

0 comments on commit 75260c9

Please sign in to comment.