28 lines
967 B
Racket
28 lines
967 B
Racket
#lang racket/base
|
|
|
|
(require racket/date racket/match racket/string
|
|
net/url-string)
|
|
|
|
(provide get-date parse-url get-user-agent-header)
|
|
|
|
(define (get-date)
|
|
(parameterize ([date-display-format 'rfc2822])
|
|
;; aaaaaaaaaaaaaaaaaaaaa
|
|
(regexp-replace
|
|
#px"[^ ]+$"
|
|
(date->string (seconds->date (* 0.001 (current-inexact-milliseconds)) #f) #t)
|
|
"GMT")))
|
|
|
|
(define (parse-url fetch-url)
|
|
(printf "fetching page: ~a\n" fetch-url)
|
|
(define parsed-url (if (string? fetch-url) (string->url fetch-url) fetch-url))
|
|
(match parsed-url
|
|
[(url scheme user host port path-absolute? path query fragment)
|
|
(define ssl? (string=? (string-downcase scheme) "https"))
|
|
(values parsed-url ssl? host
|
|
(or port (if ssl? 443 80))
|
|
(format "/~a" (string-join (map path/param-path path) "/")))]))
|
|
|
|
(define (get-user-agent-header)
|
|
(format "User-Agent: Racket/~a (net/http-client) static-generator/0.1 trans/rights" (version)))
|