@@ -61,6 +61,9 @@ fn run_app_test() {
6161
6262 app.handle_static ('testdata' , true ) or { panic (err) }
6363
64+ // Enable markdown content negotiation for testing
65+ app.enable_markdown_negotiation = true
66+
6467 if _ := app.mount_static_folder_at ('testdata' , 'static' ) {
6568 assert true == false , 'should throw invalid mount path error'
6669 } else {
@@ -126,3 +129,86 @@ fn test_upper_case_mime_type() {
126129 assert x.status () == .ok
127130 assert x.body == 'body'
128131}
132+
133+ // Content negotiation tests - Priority order
134+ // Tests verify: path.md > path.html.md > path/index.html.md
135+
136+ fn test_markdown_negotiation_priority_first () {
137+ // When all three variants exist, path.md (priority 1) is served
138+ config := http.FetchConfig{
139+ url: '${localserver} /about'
140+ header: http.new_header (key: .accept, value: 'text/markdown' )
141+ }
142+ x := http.fetch (config)!
143+
144+ assert x.status () == .ok
145+ assert x.header.get (.content_type)! == 'text/markdown'
146+ assert x.body.contains ('This is the about page in markdown format.' )
147+ assert ! x.body.contains ('about.html.md variant' )
148+ assert ! x.body.contains ('about/index.html.md variant' )
149+ }
150+
151+ fn test_markdown_negotiation_priority_second () {
152+ // When only path.html.md exists (priority 2), it is served
153+ config := http.FetchConfig{
154+ url: '${localserver} /page'
155+ header: http.new_header (key: .accept, value: 'text/markdown' )
156+ }
157+ x := http.fetch (config)!
158+
159+ assert x.status () == .ok
160+ assert x.header.get (.content_type)! == 'text/markdown'
161+ assert x.body.contains ('# Page HTML Markdown' )
162+ }
163+
164+ fn test_markdown_negotiation_directory_index () {
165+ // For directories, index.html.md is served when Accept: text/markdown
166+ config := http.FetchConfig{
167+ url: '${localserver} /sub_folder/'
168+ header: http.new_header (key: .accept, value: 'text/markdown' )
169+ }
170+ x := http.fetch (config)!
171+
172+ assert x.status () == .ok
173+ assert x.header.get (.content_type)! == 'text/markdown'
174+ assert x.body.contains ('# Index HTML Markdown' )
175+ }
176+
177+ // Direct access tests - Verifies backward compatibility
178+
179+ fn test_markdown_direct_access () {
180+ // Without Accept header
181+ x_no_header := http.get ('${localserver} /test.md' )!
182+ assert x_no_header.status () == .ok
183+ assert x_no_header.header.get (.content_type)! == 'text/markdown'
184+ assert x_no_header.body.contains ('# Test Markdown' )
185+
186+ // With Accept: text/markdown header - same result
187+ config := http.FetchConfig{
188+ url: '${localserver} /test.md'
189+ header: http.new_header (key: .accept, value: 'text/markdown' )
190+ }
191+ x_with_header := http.fetch (config)!
192+ assert x_with_header.status () == .ok
193+ assert x_with_header.header.get (.content_type)! == 'text/markdown'
194+ assert x_with_header.body.contains ('# Test Markdown' )
195+ }
196+
197+ fn test_markdown_variants_direct_access () {
198+ // All markdown variants remain accessible via their full paths
199+ x_html_md := http.get ('${localserver} /about.html.md' )!
200+ assert x_html_md.status () == .ok
201+ assert x_html_md.body.contains ('about.html.md variant' )
202+
203+ x_index := http.get ('${localserver} /about/index.html.md' )!
204+ assert x_index.status () == .ok
205+ assert x_index.body.contains ('about/index.html.md variant' )
206+ }
207+
208+ // Negative tests - Verifies correct behavior without Accept header
209+
210+ fn test_markdown_no_negotiation_without_header () {
211+ // Without Accept: text/markdown, content is not found for directories with no index.html
212+ x := http.get ('${localserver} /about' )!
213+ assert x.status () == .not_found
214+ }
0 commit comments