-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-a-url.rkt
42 lines (37 loc) · 1.38 KB
/
fetch-a-url.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#lang racket
#|
Based on https://lisp.sh/fetch-a-url/
To use "http-request" via another Racket file:
(require "./fetch-a-url.rkt") ; Update file location
(include "./fetch-a-url.rkt")
|#
;; Package "http" is not installed by default.
;; To install, execute via a shell: "raco pkg install http"
;; or via DrRacket: File -> Install Package...
(require http)
(provide http-request)
(define (http-request uri
#:redirects [redirects 10]
#:http-version [http-version "1.1"]
#:method [method "GET"]
#:data [data #""]
#:data-length [data-length #f]
#:heads [heads '(("User-Agent" . "DrRacket"))]
#:entity-reader [entity-reader read-entity/bytes])
(if (and (bytes? data)
(bytes=? data #"")
(eq? data-length #f))
(call/input-request http-version
method
uri
heads
entity-reader
#:redirects redirects)
(call/output-request http-version
method
uri
data
data-length
heads
entity-reader
#:redirects redirects)))