File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,8 @@ export default async function requestAndResultsFormatter(options: OpenGraphScrap
7272 body = decode ( Buffer . from ( bodyArrayBuffer ) , charset ) ;
7373 }
7474
75- if ( response ?. headers ?. get ( 'content-type' ) && ! response . headers . get ( 'content-type' ) ?. includes ( 'text/' ) ) {
75+ const contentType = response ?. headers ?. get ( 'content-type' ) ?. toLowerCase ( ) ;
76+ if ( contentType && ! contentType . includes ( 'text/' ) ) {
7677 throw new Error ( 'Page must return a header content-type with text/' ) ;
7778 }
7879 if ( response ?. status && ( response . status . toString ( ) . startsWith ( '4' ) || response . status . toString ( ) . startsWith ( '5' ) ) ) {
Original file line number Diff line number Diff line change @@ -709,6 +709,22 @@ describe('return ogs', function () {
709709 } ) ;
710710 } ) ;
711711
712+ it ( 'should handle case-insensitive Content-Type headers' , function ( ) {
713+ mockAgent . get ( 'http://www.test.com' )
714+ . intercept ( { path : '/' } )
715+ . reply ( 200 , basicHTML , { headers : { 'Content-Type' : 'Text/html; charset=utf-8' } } ) ;
716+
717+ return ogs ( { url : 'http://www.test.com' } )
718+ . then ( function ( data ) {
719+ expect ( data . result . success ) . to . be . eql ( true ) ;
720+ expect ( data . error ) . to . be . eql ( false ) ;
721+ expect ( data . result . ogTitle ) . to . be . eql ( 'test page' ) ;
722+ expect ( data . result . requestUrl ) . to . be . eql ( 'http://www.test.com' ) ;
723+ expect ( data . html ) . to . be . eql ( basicHTML ) ;
724+ expect ( data . response ) . to . be . a ( 'response' ) ;
725+ } ) ;
726+ } ) ;
727+
712728 it ( 'when trying to hit a non html pages based on content-type' , function ( ) {
713729 mockAgent . get ( 'http://www.test.com' )
714730 . intercept ( { path : '/' } )
You can’t perform that action at this time.
0 commit comments