http_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. "github.com/sagernet/sing/common"
  8. "github.com/sagernet/sing/common/json/badoption"
  9. )
  10. func TestHTTPSelf(t *testing.T) {
  11. startInstance(t, option.Options{
  12. Inbounds: []option.Inbound{
  13. {
  14. Type: C.TypeMixed,
  15. Tag: "mixed-in",
  16. Options: &option.HTTPMixedInboundOptions{
  17. ListenOptions: option.ListenOptions{
  18. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  19. ListenPort: clientPort,
  20. },
  21. },
  22. },
  23. {
  24. Type: C.TypeMixed,
  25. Options: &option.HTTPMixedInboundOptions{
  26. ListenOptions: option.ListenOptions{
  27. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  28. ListenPort: serverPort,
  29. },
  30. },
  31. },
  32. },
  33. Outbounds: []option.Outbound{
  34. {
  35. Type: C.TypeDirect,
  36. },
  37. {
  38. Type: C.TypeHTTP,
  39. Tag: "http-out",
  40. Options: &option.HTTPOutboundOptions{
  41. ServerOptions: option.ServerOptions{
  42. Server: "127.0.0.1",
  43. ServerPort: serverPort,
  44. },
  45. },
  46. },
  47. },
  48. Route: &option.RouteOptions{
  49. Rules: []option.Rule{
  50. {
  51. Type: C.RuleTypeDefault,
  52. DefaultOptions: option.DefaultRule{
  53. RawDefaultRule: option.RawDefaultRule{
  54. Inbound: []string{"mixed-in"},
  55. },
  56. RuleAction: option.RuleAction{
  57. Action: C.RuleActionTypeRoute,
  58. RouteOptions: option.RouteActionOptions{
  59. Outbound: "http-out",
  60. },
  61. },
  62. },
  63. },
  64. },
  65. },
  66. })
  67. testTCP(t, clientPort, testPort)
  68. }