|
1 | 1 | #lang racket/base |
2 | | -(require racket/runtime-path |
| 2 | + |
| 3 | +(require net/http-client |
| 4 | + racket/async-channel |
3 | 5 | racket/port |
4 | | - racket/list |
5 | | - web-server/servlet |
6 | | - net/http-client |
7 | | - web-server/servlet-env) |
| 6 | + racket/runtime-path |
| 7 | + version/utils |
| 8 | + web-server/http |
| 9 | + web-server/servlet-dispatch |
| 10 | + web-server/web-server) |
8 | 11 |
|
9 | | -(define-runtime-path here ".") |
| 12 | +(define-runtime-path private-key.pem |
| 13 | + "private-key.pem") |
| 14 | +(define-runtime-path server-cert.pem |
| 15 | + "server-cert.pem") |
10 | 16 |
|
11 | 17 | (module+ test |
12 | 18 | (require rackunit) |
13 | | - |
14 | | - (define-values (pipe-i pipe-o) (make-pipe)) |
15 | | - |
16 | | - (define server-t |
17 | | - (parameterize ([current-output-port pipe-o]) |
18 | | - (thread |
19 | | - (λ () |
20 | | - (serve/servlet (lambda (req) (response/xexpr `(html (body (h1 "Hello"))))) |
21 | | - #:launch-browser? #f |
22 | | - #:port 0 |
23 | | - #:listen-ip #f |
24 | | - #:ssl? #t |
25 | | - #:ssl-cert (build-path here "server-cert.pem") |
26 | | - #:ssl-key (build-path here "private-key.pem") |
27 | | - #:servlet-regexp #rx""))))) |
28 | 19 |
|
29 | | - (define the-port |
30 | | - (string->number |
31 | | - (second |
32 | | - (regexp-match #rx"localhost:([0-9]+).$" (read-line pipe-i))))) |
33 | | - |
34 | | - (define-values (status headers body) |
35 | | - (http-sendrecv "localhost" "/" #:port the-port #:ssl? #t)) |
36 | | - |
37 | | - (check-equal? status #"HTTP/1.1 200 OK") |
38 | | - (check-equal? (port->bytes body) #"<html><body><h1>Hello</h1></body></html>")) |
| 20 | + ;; Old versions of Racket don't work well with recent versions of |
| 21 | + ;; OpenSSL found in CI. So, skip this test for older Rackets. |
| 22 | + (unless (version<? (version) "8.16") |
| 23 | + (define ssl-connect@ |
| 24 | + (make-ssl-connect@ server-cert.pem private-key.pem)) |
| 25 | + (define confirmation-ch |
| 26 | + (make-async-channel)) |
| 27 | + (define stop |
| 28 | + (serve |
| 29 | + #:dispatch |
| 30 | + (dispatch/servlet |
| 31 | + (lambda (_req) |
| 32 | + (response/xexpr `(html (body (h1 "Hello")))))) |
| 33 | + #:port 0 |
| 34 | + #:confirmation-channel confirmation-ch |
| 35 | + #:dispatch-server-connect@ ssl-connect@)) |
| 36 | + (define port |
| 37 | + (sync confirmation-ch)) |
| 38 | + (when (exn:fail? port) |
| 39 | + (raise port)) |
| 40 | + (test-case "regression test for GH issue #3" |
| 41 | + (define-values (status _headers body) |
| 42 | + (http-sendrecv "localhost" "/" #:port port #:ssl? #t)) |
| 43 | + (check-equal? status #"HTTP/1.1 200 OK") |
| 44 | + (check-equal? (port->bytes body) #"<html><body><h1>Hello</h1></body></html>")) |
| 45 | + (stop))) |
0 commit comments