(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func TestIsDirectRequest(t *testing.T) { |
| 37 | tests := []struct { |
| 38 | name string |
| 39 | req *http.Request |
| 40 | want bool |
| 41 | }{ |
| 42 | { |
| 43 | name: "origin form get", |
| 44 | req: &http.Request{ |
| 45 | Method: http.MethodGet, |
| 46 | URL: &url.URL{Path: "/"}, |
| 47 | Host: "web.nacl.one", |
| 48 | }, |
| 49 | want: true, |
| 50 | }, |
| 51 | { |
| 52 | name: "absolute form get", |
| 53 | req: &http.Request{ |
| 54 | Method: http.MethodGet, |
| 55 | URL: &url.URL{Scheme: "http", Host: "openrouter.ai", Path: "/"}, |
| 56 | Host: "openrouter.ai", |
| 57 | }, |
| 58 | want: false, |
| 59 | }, |
| 60 | { |
| 61 | name: "connect", |
| 62 | req: &http.Request{ |
| 63 | Method: http.MethodConnect, |
| 64 | URL: &url.URL{Host: "openrouter.ai:443"}, |
| 65 | Host: "openrouter.ai:443", |
| 66 | }, |
| 67 | want: false, |
| 68 | }, |
| 69 | { |
| 70 | name: "trust tunnel random", |
| 71 | req: &http.Request{ |
| 72 | Method: "GETRANDOM", |
| 73 | URL: &url.URL{Path: "/32"}, |
| 74 | Host: "web.nacl.one", |
| 75 | }, |
| 76 | want: false, |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | for _, tt := range tests { |
| 81 | t.Run(tt.name, func(t *testing.T) { |
| 82 | if got := isDirectRequest(tt.req); got != tt.want { |
| 83 | t.Fatalf("isDirectRequest() = %v, want %v", got, tt.want) |
| 84 | } |
| 85 | }) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func TestDirectResponse(t *testing.T) { |
| 90 | proxy := NewProxyHandler(&Config{ |
nothing calls this directly
no test coverage detected