gopp/httpx/request.go

49 lines
685 B
Go

package httpx
import (
"github.com/d5/tengo/v2"
"net/http"
"io"
//"log"
)
type Request struct {
tengo.ObjectImpl
*http.Request
}
func (r *Request) TypeName() string {
return "*http.Request"
}
func (r *Request) String() string {
return "*http.Request{...}"
}
func (r *Request) IndexGet(
index tengo.Object,
) (tengo.Object, error) {
key, ok := tengo.ToString(index)
if !ok {
return nil, tengo.ErrInvalidIndexValueType
}
switch key {
case "url" :
return &URL{
URL: r.URL,
}, nil
case "body" :
bts, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
return &tengo.Bytes{
Value: bts,
}, nil
}
// Nothing found.
return nil, nil
}