Skip to content

Commit

Permalink
Add X-Requested-With header to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnojus committed Mar 29, 2021
1 parent 2c0dc58 commit b59bf5e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions transfer/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func FilenameFromUrl(URL string) string {
func getDownloadLink(client *http.Client, data transferData) (URL string, err error) {
url := fmt.Sprintf("%s/transfers/%s/download", baseApi, data.transferId)
req, err := createRequest("POST", url, headers{
"x-csrf-token": data.csrfToken,
"cookie": "_wt_session=" + data.wtSession,
"content-type": "application/json",
"X-CSRF-Token": data.csrfToken,
"cookie": "_wt_session=" + data.wtSession,
"content-type": "application/json",
"X-Requested-With": "XMLHttpRequest",
}, data.reqData)
if err != nil {
return
Expand All @@ -86,19 +87,22 @@ func getDownloadLink(client *http.Client, data transferData) (URL string, err er
if err != nil {
return
}
var result map[string]interface{}
var result interface{}
err = json.Unmarshal(body, &result)
if err != nil {
return
}
if URL, ok := result["direct_link"].(string); ok {
return URL, nil
}
message := "Unable to get direct link"
if e, ok := result["message"].(string); ok {
message += ": " + e
if dict, ok := result.(map[string]interface{}); ok {
if URL, ok := dict["direct_link"].(string); ok {
return URL, nil
}
message := "Unable to get direct link"
if e, ok := dict["message"].(string); ok {
message += ": " + e
}
return "", errors.New(message)
}
return "", errors.New(message)
return "", fmt.Errorf("Invalid download request response: %s", body)
}

func getTransferData(resp *http.Response) (out transferData, err error) {
Expand Down

1 comment on commit b59bf5e

@gan-of-culture
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for the really fast update 👍

Please sign in to comment.