diff --git a/src/page-file.rkt b/src/page-file.rkt index d04c135..a2490ab 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -33,13 +33,22 @@ (easy:response-headers-ref dest-res 'content-type)) (define (get-media-html url content-type) + (define proxied-url (if (config-true? 'strict_proxy) (u-proxy-url url) url)) (cond [(eq? content-type #f) `""] - [(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,url)))] + [(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,proxied-url)))] [(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type) - `(audio (@ (src ,url) (controls)))] - [(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,url) (controls)))] + `(audio (@ (src ,proxied-url) (controls)))] + [(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,proxied-url) (controls)))] [else `""])) +(module+ test + (require rackunit) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/a" "image/jpeg") (img (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fa")))) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/b" "audio/mp3") (audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fb")))) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/c" "application/ogg") (audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fc")))) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/d" "video/mp4") (video (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fd")))) + (check-equal? (get-media-html "https://example.com" "who knows") "") + (check-equal? (get-media-html #f "who knows") "")) (define (generate-results-page #:source-url source-url #:wikiname wikiname @@ -125,6 +134,7 @@ ; convert to string with error checking, error will be raised if xexp is invalid (xexp->html body)) (response/output #:code 200 + #:headers (list referrer-policy) (λ (out) (write-html body out))))))) ;(module+ test ; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")