@@ -105,6 +105,73 @@ describe('markdown pages', () => {
105105 } ) ;
106106} ) ;
107107
108+ describe ( 'Accept header content negotiation' , ( ) => {
109+ const PAGE_URL = getContentTestURL ( TEST_PAGE_URL ) ;
110+
111+ it ( 'should NOT serve markdown for Accept: text/html' , async ( ) => {
112+ const response = await fetch ( PAGE_URL , {
113+ headers : { Accept : 'text/html' } ,
114+ } ) ;
115+
116+ expect ( response . status ) . toBe ( 200 ) ;
117+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/html' ) ;
118+ } ) ;
119+
120+ it ( 'should NOT serve markdown for Accept: */*' , async ( ) => {
121+ const response = await fetch ( PAGE_URL , {
122+ headers : { Accept : '*/*' } ,
123+ } ) ;
124+
125+ expect ( response . status ) . toBe ( 200 ) ;
126+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/html' ) ;
127+ } ) ;
128+
129+ it ( 'should NOT serve markdown when text/html is preferred over text/markdown (Accept: text/html, text/markdown)' , async ( ) => {
130+ const response = await fetch ( PAGE_URL , {
131+ headers : { Accept : 'text/html, text/markdown' } ,
132+ } ) ;
133+
134+ expect ( response . status ) . toBe ( 200 ) ;
135+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/html' ) ;
136+ } ) ;
137+
138+ it ( 'should serve markdown when text/markdown is preferred over text/html (Accept: text/markdown, text/html)' , async ( ) => {
139+ const response = await fetch ( PAGE_URL , {
140+ headers : { Accept : 'text/markdown, text/html' } ,
141+ } ) ;
142+
143+ expect ( response . status ) . toBe ( 200 ) ;
144+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/markdown' ) ;
145+ } ) ;
146+
147+ it ( 'should serve markdown when text/markdown has a higher q-value (Accept: text/html;q=0.9, text/markdown)' , async ( ) => {
148+ const response = await fetch ( PAGE_URL , {
149+ headers : { Accept : 'text/html;q=0.9, text/markdown' } ,
150+ } ) ;
151+
152+ expect ( response . status ) . toBe ( 200 ) ;
153+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/markdown' ) ;
154+ } ) ;
155+
156+ it ( 'should NOT serve markdown when text/markdown has a lower q-value (Accept: text/html, text/markdown;q=0.9)' , async ( ) => {
157+ const response = await fetch ( PAGE_URL , {
158+ headers : { Accept : 'text/html, text/markdown;q=0.9' } ,
159+ } ) ;
160+
161+ expect ( response . status ) . toBe ( 200 ) ;
162+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/html' ) ;
163+ } ) ;
164+
165+ it ( 'should serve markdown for Accept: text/x-markdown' , async ( ) => {
166+ const response = await fetch ( PAGE_URL , {
167+ headers : { Accept : 'text/x-markdown' } ,
168+ } ) ;
169+
170+ expect ( response . status ) . toBe ( 200 ) ;
171+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'text/markdown' ) ;
172+ } ) ;
173+ } ) ;
174+
108175describe ( 'markdown ask responses' , ( ) => {
109176 const ASK_QUESTION = 'What is GitBook?' ;
110177 const ASK_QUESTION_HEADING = `# ${ ASK_QUESTION } ` ;
0 commit comments