Compare commits

..

No commits in common. "19aeeea60fc6c7c724206c2ba2d21f847c366d98" and "51bf087b30b8626038e4799726255510fbecbb33" have entirely different histories.

5 changed files with 16 additions and 37 deletions

View file

@ -9,8 +9,6 @@
"url-utils.rkt") "url-utils.rkt")
(provide (provide
; header to not send referers to fandom
referrer-policy
; timeout durations for http-easy requests ; timeout durations for http-easy requests
timeouts timeouts
; generates a consistent footer ; generates a consistent footer
@ -24,7 +22,6 @@
(require rackunit (require rackunit
html-writing)) html-writing))
(define referrer-policy (header #"Referrer-Policy" #"no-referrer"))
(define timeouts (easy:make-timeout-config #:lease 5 #:connect 5)) (define timeouts (easy:make-timeout-config #:lease 5 #:connect 5))
(define (application-footer source-url #:license [license-in #f]) (define (application-footer source-url #:license [license-in #f])

View file

@ -113,7 +113,6 @@
(xexp->html body)) (xexp->html body))
(response/output (response/output
#:code 200 #:code 200
#:headers (list referrer-policy)
(λ (out) (λ (out)
(write-html body out)))))) (write-html body out))))))
(module+ test (module+ test

View file

@ -33,24 +33,13 @@
(easy:response-headers-ref dest-res 'content-type)) (easy:response-headers-ref dest-res 'content-type))
(define (get-media-html url content-type) (define (get-media-html url content-type)
(define maybe-proxied-url (if (config-true? 'strict_proxy) (u-proxy-url url) url))
(cond (cond
[(eq? content-type #f) `""] [(eq? content-type #f) `""]
[(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,maybe-proxied-url)))] [(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,url)))]
[(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type) [(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type)
`(audio (@ (src ,maybe-proxied-url) (controls)))] `(audio (@ (src ,url) (controls)))]
[(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,maybe-proxied-url) (controls)))] [(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,url) (controls)))]
[else `""])) [else `""]))
(module+ test
(require rackunit)
(parameterize ([config-parameter 'strict_proxy "true"])
(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")))))
(parameterize ([config-parameter 'strict_proxy "no"])
(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 (define (generate-results-page #:source-url source-url
#:wikiname wikiname #:wikiname wikiname
@ -136,7 +125,6 @@
; convert to string with error checking, error will be raised if xexp is invalid ; convert to string with error checking, error will be raised if xexp is invalid
(xexp->html body)) (xexp->html body))
(response/output #:code 200 (response/output #:code 200
#:headers (list referrer-policy)
(λ (out) (write-html body out))))))) (λ (out) (write-html body out)))))))
;(module+ test ;(module+ test
; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor") ; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")

View file

@ -81,7 +81,6 @@
(xexp->html body)) (xexp->html body))
(response/output (response/output
#:code 200 #:code 200
#:headers (list referrer-policy)
(λ (out) (λ (out)
(write-html body out)))))) (write-html body out))))))
(module+ test (module+ test

View file

@ -152,17 +152,15 @@
(λ (v) (dict-update v 'rel (λ (s) (λ (v) (dict-update v 'rel (λ (s)
(list (string-append (car s) " noreferrer"))) (list (string-append (car s) " noreferrer")))
'("")))) '(""))))
; proxy images from inline styles, if strict_proxy is set ; proxy images from inline styles
(curry u (curry attribute-maybe-update 'style
(λ (v) (config-true? 'strict_proxy))
(λ (v) (attribute-maybe-update 'style
(λ (style) (λ (style)
(regexp-replace #rx"url\\(['\"]?(.*?)['\"]?\\)" style (regexp-replace #rx"url\\(['\"]?(.*?)['\"]?\\)" style
(λ (whole url) (λ (whole url)
(string-append (string-append
"url(" "url("
(u-proxy-url url) (u-proxy-url url)
")")))) v))) ")")))))
; and also their links, if strict_proxy is set ; and also their links, if strict_proxy is set
(curry u (curry u
(λ (v) (λ (v)
@ -170,10 +168,8 @@
(eq? element-type 'a) (eq? element-type 'a)
(has-class? "image-thumbnail" v))) (has-class? "image-thumbnail" v)))
(λ (v) (attribute-maybe-update 'href u-proxy-url v))) (λ (v) (attribute-maybe-update 'href u-proxy-url v)))
; proxy images from src attributes, if strict_proxy is set ; proxy images from src attributes
(curry u (curry attribute-maybe-update 'src u-proxy-url)
(λ (v) (config-true? 'strict_proxy))
(λ (v) (attribute-maybe-update 'src u-proxy-url v)))
; don't lazyload images ; don't lazyload images
(curry u (curry u
(λ (v) (dict-has-key? v 'data-src)) (λ (v) (dict-has-key? v 'data-src))
@ -280,8 +276,8 @@
(define headers (if redirect-msg (define headers (if redirect-msg
(let* ([dest (get-attribute 'href (bits->attributes ((query-selector (λ (t a c) (eq? t 'a)) redirect-msg))))] (let* ([dest (get-attribute 'href (bits->attributes ((query-selector (λ (t a c) (eq? t 'a)) redirect-msg))))]
[value (bytes-append #"0;url=" (string->bytes/utf-8 dest))]) [value (bytes-append #"0;url=" (string->bytes/utf-8 dest))])
(list (header #"Refresh" value) referrer-policy)) (list (header #"Refresh" value)))
(list referrer-policy))) (list)))
(when (config-true? 'debug) (when (config-true? 'debug)
; used for its side effects ; used for its side effects
; convert to string with error checking, error will be raised if xexp is invalid ; convert to string with error checking, error will be raised if xexp is invalid