|
7 | 7 | (import (liii hash-table) |
8 | 8 | (liii alist)) |
9 | 9 | (export http-head http-get http-post http-ok? |
10 | | - http-stream-get http-stream-post) |
| 10 | + http-stream-get http-stream-post |
| 11 | + http-async-get http-async-post http-async-head http-poll http-wait-all) |
11 | 12 | (begin |
12 | 13 |
|
13 | 14 | (define (http-ok? r) |
|
65 | 66 | (g_http-stream-post url params data '(("Content-Type" . "text/plain")) proxy userdata callback)) |
66 | 67 | (else (g_http-stream-post url params data headers proxy userdata callback)))) |
67 | 68 |
|
| 69 | +;; Async HTTP API wrapper functions |
| 70 | + |
| 71 | +(define* (http-async-get url callback (params '()) (headers '()) (proxy '())) |
| 72 | + (when (not (alist? params)) |
| 73 | + (type-error params "is not a association list")) |
| 74 | + (when (not (alist? proxy)) |
| 75 | + (type-error proxy "is not a association list")) |
| 76 | + (when (not (procedure? callback)) |
| 77 | + (type-error callback "is not a procedure")) |
| 78 | + (g_http-async-get url params headers proxy callback)) |
| 79 | + |
| 80 | +(define* (http-async-post url callback (params '()) (data "") (headers '()) (proxy '())) |
| 81 | + (when (not (alist? params)) |
| 82 | + (type-error params "is not a association list")) |
| 83 | + (when (not (alist? proxy)) |
| 84 | + (type-error proxy "is not a association list")) |
| 85 | + (when (not (procedure? callback)) |
| 86 | + (type-error callback "is not a procedure")) |
| 87 | + (cond ((and (string? data) (> (string-length data) 0) (null? headers)) |
| 88 | + (g_http-async-post url params data '(("Content-Type" . "text/plain")) proxy callback)) |
| 89 | + (else (g_http-async-post url params data headers proxy callback)))) |
| 90 | + |
| 91 | +(define* (http-async-head url callback (params '()) (headers '()) (proxy '())) |
| 92 | + (when (not (alist? params)) |
| 93 | + (type-error params "is not a association list")) |
| 94 | + (when (not (alist? proxy)) |
| 95 | + (type-error proxy "is not a association list")) |
| 96 | + (when (not (procedure? callback)) |
| 97 | + (type-error callback "is not a procedure")) |
| 98 | + (g_http-async-head url params headers proxy callback)) |
| 99 | + |
| 100 | +(define (http-poll) |
| 101 | + (g_http-poll)) |
| 102 | + |
| 103 | +(define* (http-wait-all (timeout -1)) |
| 104 | + (g_http-wait-all timeout)) |
| 105 | + |
68 | 106 | ) ; end of begin |
69 | 107 | ) ; end of define-library |
70 | 108 |
|
0 commit comments