headers_test.go 739 B

12345678910111213141516171819202122232425262728293031
  1. package jsc_test
  2. import (
  3. "fmt"
  4. "net/http"
  5. "reflect"
  6. "testing"
  7. "github.com/sagernet/sing-box/script/jsc"
  8. "github.com/dop251/goja"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestHeaders(t *testing.T) {
  12. runtime := goja.New()
  13. runtime.Set("headers", jsc.HeadersToValue(runtime, http.Header{
  14. "My-Header": []string{"My-Value1", "My-Value2"},
  15. }))
  16. headers := runtime.Get("headers").(*goja.Object).Get("My-Header").(*goja.Object)
  17. fmt.Println(reflect.ValueOf(headers.Export()).Type().String())
  18. }
  19. func TestBody(t *testing.T) {
  20. runtime := goja.New()
  21. _, err := runtime.RunString(`
  22. var responseBody = new Uint8Array([1, 2, 3, 4, 5])
  23. `)
  24. require.NoError(t, err)
  25. fmt.Println(reflect.TypeOf(runtime.Get("responseBody").Export()))
  26. }