- (if (= 200 status)
- (begin
- (make-parent-directory* cache-file-path)
- (call-with-output-file cache-file-path
- (curry copy-port body-input)
- #:exists 'replace))
- (raise status))]
+ (match status
+ [200
+ (let ([etag (header-get headers #"ETag")]
+ [lmod (header-get headers #"Last-Modified")])
+ (if (and etag
+ (file-exists? cached-etag-path)
+ (bytes=? etag (file->bytes cached-etag-path)))
+ (log-info "ETags match, skipping the rest of ~v" (url->string u))
+ (begin
+ (log-info
+ "Downloading the rest of ~v. ETag: ~a, Last-Modified: ~v"
+ (url->string u) etag lmod)
+ (make-parent-directory* cached-object-path)
+ (make-parent-directory* cached-etag-path)
+ (make-parent-directory* cached-lmod-path)
+ (call-with-output-file cached-object-path
+ (curry copy-port body-input)
+ #:exists 'replace)
+ (when etag
+ (display-to-file etag cached-etag-path #:exists 'replace))
+ (when lmod
+ (display-to-file etag cached-lmod-path #:exists 'replace))))
+ (close-input-port body-input))]
+ [_
+ (raise status)])]