2024-06-06 00:13:12 +03:00
|
|
|
package httpx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/d5/tengo/v2"
|
|
|
|
"net/http"
|
|
|
|
"io"
|
|
|
|
//"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Request struct {
|
|
|
|
*http.Request
|
2024-07-31 19:21:24 +03:00
|
|
|
tengo.ObjectImpl
|
2024-06-06 00:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) TypeName() string {
|
2024-07-31 19:21:24 +03:00
|
|
|
return "http.Request"
|
2024-06-06 00:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) String() string {
|
2024-07-31 19:21:24 +03:00
|
|
|
return "http.Request{...}"
|
2024-06-06 00:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|