#lang racket/base (provide random-hex-string extend-url-string-query) (require (only-in file/sha1 bytes->hex-string)) (require (only-in racket/random crypto-random-bytes)) (require net/url) (module+ test (require rackunit)) (define (random-hex-string half-length) (bytes->hex-string (crypto-random-bytes half-length))) (define (extend-url-string-query urlstr extension) (define u (string->url urlstr)) (url->string (struct-copy url u [query (append (url-query u) extension)]))) (module+ test (check-equal? (extend-url-string-query "http://localhost/" '((a . "hi"))) "http://localhost/?a=hi") (check-equal? (extend-url-string-query "http://localhost/" '()) "http://localhost/") (check-equal? (extend-url-string-query "http://localhost?foo=bar" '()) "http://localhost?foo=bar") (check-equal? (extend-url-string-query "http://localhost/?foo=bar" '()) "http://localhost/?foo=bar") (check-equal? (extend-url-string-query "http://localhost?foo=bar" '((a . "hi"))) "http://localhost?foo=bar&a=hi") (check-equal? (extend-url-string-query "http://localhost/?foo=bar" '((a . "hi"))) "http://localhost/?foo=bar&a=hi"))