csrf token
This commit is contained in:
parent
41119b5966
commit
a09b6e34a3
19
asset.go
19
asset.go
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AssetUploadOptions struct {
|
type AssetUploadOptions struct {
|
||||||
@ -57,10 +58,8 @@ func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUp
|
|||||||
|
|
||||||
endpoint.RawQuery = query.Encode()
|
endpoint.RawQuery = query.Encode()
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint.String(), f)
|
req, err := http.NewRequest("POST", endpoint.String(), nil)
|
||||||
req.Header.Set("user-agent", "Roblox/WinInet")
|
req.Header.Set("user-agent", "Roblox")
|
||||||
req.Header.Set("content-type", "application/xml")
|
|
||||||
req.Header.Set("accept", "application/json")
|
|
||||||
|
|
||||||
// Perform request
|
// Perform request
|
||||||
resp, err := s.client.Do(req)
|
resp, err := s.client.Do(req)
|
||||||
@ -69,6 +68,18 @@ func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUp
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 403 && resp.Header.Get("X-Csrf-Token") != "" {
|
||||||
|
req, err := http.NewRequest("POST", endpoint.String(), f)
|
||||||
|
req.Header.Set("user-agent", "Roblox")
|
||||||
|
req.Header.Set("x-csrf-token", strings.Trim(resp.Header["X-Csrf-Token"][0], " "))
|
||||||
|
// Perform request
|
||||||
|
resp, err = s.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return aresp, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return aresp, fmt.Errorf(resp.Status)
|
return aresp, fmt.Errorf(resp.Status)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user