Skip to content

Commit acf7707

Browse files
LiberalArtistsamth
authored andcommitted
typed/web-server/http: update types (typed-racket-more v1.10) (#817)
- Weaken the types of `response-output` and the `#:output` argument to `response/output` from `Void` to `Any`, corresponding to <racket/web-server@a93685> and v1.2 of the `web-server-lib`. The return type should really be `AnyValues` to match the contract `any`, but Typed Racket can't generate a contract for `AnyValues`. - Update the types for cookie-related functions to reflect the re-implementation based on `net/cookies/server` from <racket/web-server@7974d4d>. This commit adds only as much of `typed/net/cookies/server` and `typed/net/cookies/common` as needed for `typed/web-server/http`. - Document that `net/cookie` is deprecated. - Update the types for `valid-id-cookie?` and `request-id-cookie` to support the `#:shelf-life` argument added in <racket/web-server@626ad02>. - Add the value `temporarily/same-method` with the type `Redirection-Status`, corresponding to <racket/web-server@4601f4>. - Correct the types of `response-seconds` and the corresponding arguments to `response/full`, `response/output`, and `response/xexpr` to use `Real`. While this corresponds to <racket/web-server#61>, using response values containing complex numbers would cause runtime errors even before this: the `response-seconds` is passed to `seconds->date`.
1 parent ade0dff commit acf7707

7 files changed

Lines changed: 163 additions & 36 deletions

File tree

‎typed-racket-doc/info.rkt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(define collection 'multi)
44

55
(define build-deps '("net-doc"
6+
"net-cookies-doc"
67
"scheme-lib"
78
"srfi-lite-lib"
89
"r6rs-doc"
@@ -14,7 +15,7 @@
1415
"pict-lib"
1516
("typed-racket-lib" #:version "1.10")
1617
"typed-racket-compatibility"
17-
"typed-racket-more"
18+
("typed-racket-more" #:version "1.10")
1819
"racket-doc"
1920
"draw-lib"))
2021
(define deps '("base"))

‎typed-racket-doc/typed-racket/scribblings/reference/libraries.scrbl‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,29 @@ exported by @racketmodname[typed/json].
9494
@defmodule/incl[typed/mred/mred]
9595
@defmodule/incl[typed/net/base64]
9696
@defmodule/incl[typed/net/cgi]
97+
@defmodule/incl[typed/net/cookies]
98+
@defmodule/incl[typed/net/cookies/common]
99+
@history[#:added "1.10"]
100+
101+
@defmodule/incl[typed/net/cookies/server]
102+
103+
@deftype[Cookie]{
104+
Describes a server-side @hyperlink["https://tools.ietf.org/html/rfc6265.html"]{RFC 6265}
105+
HTTP cookie, as implemented by @racketmodname[net/cookies/server].
106+
}
107+
108+
@history[#:added "1.10"]
109+
97110
@defmodule/incl[typed/net/cookie]
98111

112+
@deprecated[@racketmodname[typed/net/cookies]]{
113+
This library is deprecated for the same reasons
114+
that @racketmodname[net/cookie] is deprecated.
115+
}
116+
99117
@deftype[Cookie]{
100-
Describes an HTTP cookie as implemented by @racketmodname[net/cookie].
118+
Describes an HTTP cookie as implemented by @racketmodname[net/cookie],
119+
which is deprecated in favor of @racketmodname[net/cookies].
101120
}
102121

103122
@defmodule/incl[typed/net/dns]
@@ -229,6 +248,11 @@ and the @racket[URL] and @racket[Path/Param] types from
229248
@defmodule/incl[typed/syntax/stx]
230249
@defmodule/incl[typed/web-server/configuration/responders]
231250
@defmodule/incl[typed/web-server/http]
251+
252+
@history[#:changed "1.10"
253+
@elem{Updated to reflect @racketmodname[web-server/http]
254+
version 1.3.}]
255+
232256
@defmodule/incl[typed/db]
233257
@defmodule/incl[typed/db/base]
234258
@defmodule/incl[typed/db/sqlite3]

‎typed-racket-more/info.rkt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
(define deps '("srfi-lite-lib"
66
"base"
77
"net-lib"
8-
"web-server-lib"
8+
"net-cookies-lib"
9+
["web-server-lib" #:version "1.3"]
910
["db-lib" #:version "1.5"]
1011
"draw-lib"
1112
"rackunit-lib"
@@ -25,4 +26,4 @@
2526

2627
(define pkg-authors '(samth stamourv))
2728

28-
(define version "1.9")
29+
(define version "1.10")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#lang typed/racket/base
2+
3+
(require "cookies/server.rkt"
4+
"cookies/common.rkt")
5+
6+
(provide (all-from-out "cookies/server.rkt")
7+
(all-from-out "cookies/common.rkt"))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#lang typed/racket/base
2+
3+
(require (for-syntax racket/base))
4+
5+
(define-syntax require/typed/provide-string-predicates
6+
(syntax-rules ()
7+
[(_ id)
8+
(begin (: id (-> Any Boolean : #:+ String))
9+
(provide id)
10+
(require/typed
11+
net/cookies/common
12+
[(id untyped-id) (-> Any Boolean)])
13+
(define (id v)
14+
(and (string? v)
15+
(untyped-id v))))]
16+
[(_ id ...)
17+
(begin (require/typed/provide-string-predicates id) ...)]))
18+
19+
(require/typed/provide-string-predicates
20+
cookie-name?
21+
cookie-value?
22+
path/extension-value?
23+
domain-value?)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#lang typed/racket/base
2+
3+
(require typed/racket/date)
4+
5+
(require/typed/provide
6+
net/cookies/server
7+
#| ; a cookie is this, but the cookie constructor isn't provided
8+
[#:struct cookie
9+
([name : String]
10+
[value : String]
11+
[expires : (U #f Date)]
12+
[max-age : (U #f Exact-Positive-Integer)]
13+
[domain : (U #f String)]
14+
[path : (U #f String)]
15+
[secure? : Boolean] ;; yes, really not Any
16+
[http-only? : Boolean] ;; yes, really not Any
17+
[extension : (U #f String)])]
18+
|#
19+
[#:opaque Cookie cookie?]
20+
[make-cookie
21+
(->* [String String]
22+
[#:expires (U #f date)
23+
#:max-age (U #f Exact-Positive-Integer)
24+
#:domain (U #f String)
25+
#:path (U #f String)
26+
#:secure? Boolean ;; yes, really not Any
27+
#:http-only? Boolean ;; yes, really not Any
28+
#:extension (U #f String)]
29+
Cookie)]
30+
)

‎typed-racket-more/typed/web-server/http.rkt‎

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#lang typed/racket
22

3-
(require typed/net/url)
3+
(require typed/net/url
4+
typed/racket/date)
45

56
(provide (all-defined-out))
67

@@ -57,65 +58,104 @@
5758
[#:struct response
5859
([code : Natural]
5960
[message : Bytes]
60-
[seconds : Natural]
61+
[seconds : Real]
6162
[mime : (Option Bytes)]
6263
[headers : (Listof Header)]
63-
[output : (-> Output-Port Void)])]
64+
[output : (-> Output-Port Any)])]
6465
[response/full
6566
(-> Natural
6667
Bytes
67-
Number
68+
Real
6869
(Option Bytes)
6970
(Listof Header)
7071
(Listof Bytes)
7172
Response)]
7273
[response/output
73-
(-> (-> Output-Port Void)
74+
(-> (-> Output-Port Any)
7475
[#:code Natural]
7576
[#:message Bytes]
76-
[#:seconds Number]
77+
[#:seconds Real]
7778
[#:mime-type (Option Bytes)]
7879
[#:headers (Listof Header)]
7980
Response)]
8081
[TEXT/HTML-MIME-TYPE Bytes])
8182

83+
;; For backwards compatability:
84+
;; these bindings are not and never were
85+
;; exported by web-server/http,
86+
;; but they were exported by previous versions of
87+
;; typed/web-server/http based on net/cookie.
8288

83-
(require/typed/provide net/cookie
84-
[#:opaque Cookie cookie?]
85-
[#:opaque Cookie-Name cookie-name?]
86-
[#:opaque Cookie-Value cookie-value?]
87-
[#:opaque Valid-Domain valid-domain?])
89+
(require (only-in "../net/cookies/server.rkt"
90+
Cookie
91+
cookie?)
92+
(only-in "../net/cookies/common.rkt"
93+
cookie-name?
94+
cookie-value?
95+
[domain-value? valid-domain?]))
8896

89-
(require/typed/provide web-server/http/cookie
90-
[make-cookie
91-
(-> Cookie-Name Cookie-Value
92-
[#:comment (Option String)]
93-
[#:domain (Option Valid-Domain)]
94-
[#:max-age (Option Natural)]
95-
[#:path (Option String)]
96-
[#:expires (Option String)]
97-
[#:secure? (Option Boolean)]
98-
Cookie)]
99-
[cookie->header
100-
(-> Cookie
101-
Header)])
97+
(define-type Cookie-Name String)
98+
(define-type Cookie-Value String)
99+
(define-type Valid-Domain String)
100+
101+
(provide (all-from-out "../net/cookies/server.rkt")
102+
(all-from-out "../net/cookies/common.rkt")
103+
Cookie-Name
104+
Cookie-Value
105+
Valid-Domain)
106+
107+
(require/typed/provide
108+
web-server/http/cookie
109+
[make-cookie
110+
(-> String String
111+
[#:comment Any]
112+
[#:domain (Option String)]
113+
[#:max-age (Option Natural)]
114+
[#:path (Option String)]
115+
[#:expires (Option (U date String))]
116+
[#:extension (Option String)]
117+
;; yes, these are really different
118+
;; than for typed/net/cookies/server
119+
[#:secure? Any]
120+
[#:http-only? Any]
121+
Cookie)]
122+
[cookie->header
123+
(-> Cookie
124+
Header)])
102125

103126
(require/typed/provide web-server/http/id-cookie
104127
[make-id-cookie
105-
(-> Cookie-Name
128+
(-> String
106129
Bytes
107-
Cookie-Value
130+
String
108131
[#:path (Option String)]
132+
[#:expires (Option date)]
133+
[#:max-age (Option Exact-Positive-Integer)]
134+
[#:domain (Option String)]
135+
[#:extension (Option String)]
136+
;; yes, these are really different
137+
;; than for typed/net/cookies/server
138+
[#:secure? Any]
139+
[#:http-only? Any]
109140
Cookie)]
110141
[request-id-cookie
111-
(-> Cookie-Name
142+
(-> String
112143
Bytes
113144
Request
114-
#:timeout Number
115-
(Option Cookie-Value))]
145+
[#:timeout Number]
146+
[#:shelf-life Real]
147+
(Option String))]
148+
[valid-id-cookie?
149+
(-> Any ;; yes, this is really Any
150+
#:name String
151+
#:key Bytes
152+
[#:timeout Number]
153+
[#:shelf-life Real]
154+
(Option String))]
116155
[logout-id-cookie
117-
(-> Cookie-Name
156+
(-> String
118157
[#:path (Option String)]
158+
[#:domain (Option String)]
119159
Cookie)]
120160
[make-secret-salt/file
121161
(-> Path-String
@@ -125,7 +165,7 @@
125165
[#:struct client-cookie
126166
([name : String]
127167
[value : String]
128-
[domain : (Option Valid-Domain)]
168+
[domain : (Option String)]
129169
[path : (Option String)])]
130170
[request-cookies
131171
(-> Request
@@ -139,6 +179,7 @@
139179
Response)]
140180
[permanently Redirection-Status]
141181
[temporarily Redirection-Status]
182+
[temporarily/same-method Redirection-Status]
142183
[see-other Redirection-Status])
143184

144185
(require/typed/provide web-server/http/basic-auth
@@ -170,7 +211,7 @@
170211
(-> Any ;;; it should be `xexpr?`ed value, but `Any` also works well.
171212
[#:code Natural]
172213
[#:message Bytes]
173-
[#:seconds Number]
214+
[#:seconds Real]
174215
[#:mime-type (Option Bytes)]
175216
[#:headers (Listof Header)]
176217
[#:cookies (Listof Cookie)]

0 commit comments

Comments
 (0)