forked from web3-protocol/web3protocol-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode-manual.go
29 lines (24 loc) · 868 Bytes
/
mode-manual.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package web3protocol
import (
"mime"
"strings"
)
func (client *Client) parseManualModeUrl(web3Url *Web3URL, urlMainParts map[string]string) (err error) {
// Path must be at least "/"
path := urlMainParts["path"]
if len(path) == 0 {
path = "/"
}
web3Url.ContractCallMode = ContractCallModeCalldata
web3Url.Calldata = []byte(path)
web3Url.ContractReturnProcessing = ContractReturnProcessingDecodeABIEncodedBytes
// Default MIME type is text/html
web3Url.DecodedABIEncodedBytesMimeType = "text/html"
// The path can contain an extension, which will override the mime type to use
pathnameParts := strings.Split(urlMainParts["pathname"], ".")
if len(pathnameParts) > 1 {
// If no mime type is found, this will return empty string
web3Url.DecodedABIEncodedBytesMimeType = mime.TypeByExtension("." + pathnameParts[len(pathnameParts)-1])
}
return
}