Commit ad4f3980 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Clean up runtime HTTP request functions.

parent c68ed1a2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Add missing fields to tournament end and reset JS runtime hooks.
- Add support for removing channel messages to all runtimes.
- Allow devconsole group view to add new members.
- Allow `DELETE` and `HEAD` methods in runtime HTTP request functions.

### Changed
- Stricter validation of limit in runtime storage list operations.
@@ -17,6 +18,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Renamed `groupsGetRandom` to `groups_get_random` in the Lua runtime for consistency.
- Accept Google IAP receipts with or without wrapper structures.
- Update Nakama logos.
- Stricter early validation of method parameter in Lua runtime HTTP request function.

### Fixed
- Fix response selection in purchase lookups by identifier.
+9 −2
Original line number Diff line number Diff line
@@ -584,8 +584,15 @@ func (n *runtimeJavascriptNakamaModule) httpRequest(r *goja.Runtime) func(goja.F
			panic(r.NewTypeError("URL string cannot be empty."))
		}

		if !(method == "GET" || method == "POST" || method == "PUT" || method == "PATCH") {
			panic(r.NewTypeError("Invalid method must be one of: 'get', 'post', 'put', 'patch'."))
		switch method {
		case http.MethodGet:
		case http.MethodPost:
		case http.MethodPut:
		case http.MethodPatch:
		case http.MethodDelete:
		case http.MethodHead:
		default:
			panic(r.NewTypeError("Invalid method must be one of: 'get', 'post', 'put', 'patch', 'delete', 'head'."))
		}

		var requestBody io.Reader
+12 −3
Original line number Diff line number Diff line
@@ -923,15 +923,24 @@ func (n *RuntimeLuaNakamaModule) uuidStringToBytes(l *lua.LState) int {
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeLuaNakamaModule) httpRequest(l *lua.LState) int {
	url := l.CheckString(1)
	method := l.CheckString(2)
	method := strings.ToUpper(l.CheckString(2))
	headers := l.CheckTable(3)
	body := l.OptString(4, "")

	if url == "" {
		l.ArgError(1, "expects URL string")
		return 0
	}
	if method == "" {
		l.ArgError(2, "expects method string")

	switch method {
	case http.MethodGet:
	case http.MethodPost:
	case http.MethodPut:
	case http.MethodPatch:
	case http.MethodDelete:
	case http.MethodHead:
	default:
		l.ArgError(2, "expects method to be one of: 'get', 'post', 'put', 'patch', 'delete', 'head'")
		return 0
	}