@@ -45,6 +45,46 @@ describe('Resolve trailing slash', () => {
45
45
expect ( loc . pathname ) . toBe ( '/the/example/endpoint/without/trailing/slash' )
46
46
expect ( loc . searchParams . get ( 'exampleParam' ) ) . toBe ( '1' )
47
47
} )
48
+
49
+ it ( 'should handle HEAD request for root path correctly' , async ( ) => {
50
+ const resp = await app . request ( '/' , { method : 'HEAD' } )
51
+
52
+ expect ( resp ) . not . toBeNull ( )
53
+ expect ( resp . status ) . toBe ( 200 )
54
+ } )
55
+
56
+ it ( 'should handle HEAD request for path without trailing slash correctly' , async ( ) => {
57
+ const resp = await app . request ( '/the/example/endpoint/without/trailing/slash' , {
58
+ method : 'HEAD' ,
59
+ } )
60
+
61
+ expect ( resp ) . not . toBeNull ( )
62
+ expect ( resp . status ) . toBe ( 200 )
63
+ } )
64
+
65
+ it ( 'should handle HEAD request for path with trailing slash correctly' , async ( ) => {
66
+ const resp = await app . request ( '/the/example/endpoint/without/trailing/slash/' , {
67
+ method : 'HEAD' ,
68
+ } )
69
+ const loc = new URL ( resp . headers . get ( 'location' ) ! )
70
+
71
+ expect ( resp ) . not . toBeNull ( )
72
+ expect ( resp . status ) . toBe ( 301 )
73
+ expect ( loc . pathname ) . toBe ( '/the/example/endpoint/without/trailing/slash' )
74
+ } )
75
+
76
+ it ( 'should preserve query parameters when redirecting HEAD requests' , async ( ) => {
77
+ const resp = await app . request (
78
+ '/the/example/endpoint/without/trailing/slash/?exampleParam=1' ,
79
+ { method : 'HEAD' }
80
+ )
81
+ const loc = new URL ( resp . headers . get ( 'location' ) ! )
82
+
83
+ expect ( resp ) . not . toBeNull ( )
84
+ expect ( resp . status ) . toBe ( 301 )
85
+ expect ( loc . pathname ) . toBe ( '/the/example/endpoint/without/trailing/slash' )
86
+ expect ( loc . searchParams . get ( 'exampleParam' ) ) . toBe ( '1' )
87
+ } )
48
88
} )
49
89
50
90
describe ( 'appendTrailingSlash middleware' , ( ) => {
@@ -100,5 +140,51 @@ describe('Resolve trailing slash', () => {
100
140
expect ( loc . pathname ) . toBe ( '/the/example/endpoint/with/trailing/slash/' )
101
141
expect ( loc . searchParams . get ( 'exampleParam' ) ) . toBe ( '1' )
102
142
} )
143
+
144
+ it ( 'should handle HEAD request for root path correctly' , async ( ) => {
145
+ const resp = await app . request ( '/' , { method : 'HEAD' } )
146
+
147
+ expect ( resp ) . not . toBeNull ( )
148
+ expect ( resp . status ) . toBe ( 200 )
149
+ } )
150
+
151
+ it ( 'should handle HEAD request for file-like paths correctly' , async ( ) => {
152
+ const resp = await app . request ( '/the/example/simulate/a.file' , { method : 'HEAD' } )
153
+
154
+ expect ( resp ) . not . toBeNull ( )
155
+ expect ( resp . status ) . toBe ( 200 )
156
+ } )
157
+
158
+ it ( 'should handle HEAD request for path with trailing slash correctly' , async ( ) => {
159
+ const resp = await app . request ( '/the/example/endpoint/with/trailing/slash/' , {
160
+ method : 'HEAD' ,
161
+ } )
162
+
163
+ expect ( resp ) . not . toBeNull ( )
164
+ expect ( resp . status ) . toBe ( 200 )
165
+ } )
166
+
167
+ it ( 'should redirect HEAD request for path without trailing slash to one with it' , async ( ) => {
168
+ const resp = await app . request ( '/the/example/endpoint/with/trailing/slash' , {
169
+ method : 'HEAD' ,
170
+ } )
171
+ const loc = new URL ( resp . headers . get ( 'location' ) ! )
172
+
173
+ expect ( resp ) . not . toBeNull ( )
174
+ expect ( resp . status ) . toBe ( 301 )
175
+ expect ( loc . pathname ) . toBe ( '/the/example/endpoint/with/trailing/slash/' )
176
+ } )
177
+
178
+ it ( 'should preserve query parameters when redirecting HEAD requests' , async ( ) => {
179
+ const resp = await app . request ( '/the/example/endpoint/with/trailing/slash?exampleParam=1' , {
180
+ method : 'HEAD' ,
181
+ } )
182
+ const loc = new URL ( resp . headers . get ( 'location' ) ! )
183
+
184
+ expect ( resp ) . not . toBeNull ( )
185
+ expect ( resp . status ) . toBe ( 301 )
186
+ expect ( loc . pathname ) . toBe ( '/the/example/endpoint/with/trailing/slash/' )
187
+ expect ( loc . searchParams . get ( 'exampleParam' ) ) . toBe ( '1' )
188
+ } )
103
189
} )
104
190
} )
0 commit comments