Add typed/web-server/http.rkt, typed/web-server/configuration/responders.rkt

Closes #153.
This commit is contained in:
WarGrey Gyoudmon Ju 2015-06-28 16:36:52 +08:00 committed by Sam Tobin-Hochstadt
parent e0cbc15625
commit dc73660242
4 changed files with 200 additions and 0 deletions

View File

@ -79,6 +79,7 @@ The following libraries are included with Typed Racket in the
@defmodule/incl[typed/openssl]
@defmodule/incl[typed/pict]
@defmodule[typed/racket/async-channel #:no-declare @history[#:added "1.1"]]
@defmodule/incl[typed/openssl]
@defmodule/incl[typed/racket/date]
@defmodule/incl[typed/racket/draw]
@defmodule/incl[typed/racket/gui]
@ -92,6 +93,8 @@ The following libraries are included with Typed Racket in the
@defmodule/incl[typed/srfi/14]
@defmodule/incl[typed/srfi/19]
@defmodule/incl[typed/syntax/stx]
@defmodule/incl[typed/web-server/configuration/responders]
@defmodule/incl[typed/web-server/http]
In some cases, these typed adapters may not contain all of exports of the
original module, or their types may be more limited.

View File

@ -5,6 +5,7 @@
(define deps '("srfi-lite-lib"
"base"
"net-lib"
"web-server-lib"
"draw-lib"
"rackunit-lib"
"rackunit-gui"

View File

@ -0,0 +1,18 @@
#lang typed/racket
(require "../http.rkt")
(require typed/net/url)
(require/typed/provide web-server/configuration/responders
[file-response (-> Natural Bytes Path-String Header * Response)]
[servlet-loading-responder (-> URL exn Response)]
[gen-servlet-not-found (-> Path-String (-> URL Response))]
[servlet-error-responder (-> URL exn Response)]
[gen-servlet-responder (-> Path-String (-> URL exn Response))]
[gen-servlets-refreshed (-> Path-String (-> Response))]
[gen-passwords-refreshed (-> Path-String (-> Response))]
[gen-authentication-responder (-> Path-String (-> URL Header Response))]
[gen-protocol-responder (-> Path-String (-> URL Response))]
[gen-file-not-found-responder (-> Path-String (-> Request Response))]
[gen-collect-garbage-responder (-> Path-String (-> Response))])

View File

@ -0,0 +1,178 @@
#lang typed/racket
(require typed/net/url)
(provide (all-defined-out))
(define-type Header header)
(define-type Binding binding)
(define-type Request request)
(define-type Response response)
(define-type Client-Cookie client-cookie)
(define-type Digest-Credentials (Listof (Pairof Symbol String)))
(define-type Username*Realm->Password (-> String String String))
(define-type Username*Realm->Digest-HA1 (-> String String Bytes))
(require/typed/provide web-server/http/request-structs
[#:struct header
([field : Bytes]
[value : Bytes])
#:extra-constructor-name make-header]
[#:struct binding
([id : Bytes])
#:extra-constructor-name make-binding]
[#:struct (binding:form binding)
([value : Bytes])
#:extra-constructor-name make-binding:form]
[#:struct (binding:file binding)
([filename : Bytes]
[headers : (Listof Header)]
[content : Bytes])
#:extra-constructor-name make-binding:file]
[#:struct request
([method : Bytes]
[uri : URL]
[headers/raw : (Listof Header)]
[bindings/raw-promise : (Promise (Listof Binding))]
[post-data/raw : (Option Bytes)]
[host-ip : String]
[host-port : Natural]
[client-ip : String])
#:extra-constructor-name make-request]
[headers-assq*
(-> Bytes
(Listof Header)
(Option Header))]
[bindings-assq
(-> Bytes
(Listof Binding)
(Option Binding))]
[bindings-assq-all
(-> Bytes
(Listof Binding)
(Listof Binding))])
(require/typed/provide web-server/http/response-structs
[#:struct response
([code : Natural]
[message : Bytes]
[seconds : Natural]
[mime : (Option Bytes)]
[headers : (Listof Header)]
[output : (-> Output-Port Void)])]
[response/full
(-> Natural
Bytes
Number
(Option Bytes)
(Listof Header)
(Listof Bytes)
Response)]
[response/output
(-> (-> Output-Port Void)
[#:code Natural]
[#:message Bytes]
[#:seconds Number]
[#:mime-type (Option Bytes)]
[#:headers (Listof Header)]
Response)]
[TEXT/HTML-MIME-TYPE Bytes])
(require/typed/provide net/cookie
[#:opaque Cookie cookie?]
[#:opaque Cookie-Name cookie-name?]
[#:opaque Cookie-Value cookie-value?]
[#:opaque Valid-Domain valid-domain?])
(require/typed/provide web-server/http/cookie
[make-cookie
(-> Cookie-Name Cookie-Value
[#:comment (Option String)]
[#:domain (Option Valid-Domain)]
[#:max-age (Option Natural)]
[#:path (Option String)]
[#:expires (Option String)]
[#:secure? (Option Boolean)]
Cookie)]
[cookie->header
(-> Cookie
Header)])
(require/typed/provide web-server/http/id-cookie
[make-id-cookie
(-> Cookie-Name
Bytes
Cookie-Value
[#:path (Option String)]
Cookie)]
[request-id-cookie
(-> Cookie-Name
Bytes
Request
#:timeout Number
(Option Cookie-Value))]
[logout-id-cookie
(-> Cookie-Name
[#:path (Option String)]
Cookie)]
[make-secret-salt/file
(-> Path-String
Bytes)])
(require/typed/provide web-server/http/cookie-parse
[#:struct client-cookie
([name : String]
[value : String]
[domain : (Option Valid-Domain)]
[path : (Option String)])]
[request-cookies
(-> Request
(Listof Client-Cookie))])
(require/typed/provide web-server/http/redirect
[#:opaque Redirection-Status redirection-status?]
[redirect-to
(->* (String)
(Redirection-Status #:headers (Listof Header))
Response)]
[permanently Redirection-Status]
[temporarily Redirection-Status]
[see-other Redirection-Status])
(require/typed/provide web-server/http/basic-auth
[make-basic-auth-header
(-> String
Header)]
[request->basic-credentials
(-> Request
(Option (Pairof Bytes Bytes)))])
(require/typed/provide web-server/http/digest-auth
[make-digest-auth-header
(-> String
String
String
Header)]
[request->digest-credentials
(-> Request
(Option Digest-Credentials))]
[make-check-digest-credentials
(-> Username*Realm->Digest-HA1
(-> String Digest-Credentials Boolean))]
[password->digest-HA1
(-> Username*Realm->Password
Username*Realm->Digest-HA1)])
(require/typed/provide web-server/http/xexpr
[response/xexpr
(-> Any ;;; it should be `xexpr?`ed value, but `Any` also works well.
[#:code Natural]
[#:message Bytes]
[#:seconds Number]
[#:mime-type (Option Bytes)]
[#:headers (Listof Header)]
[#:cookies (Listof Cookie)]
[#:preamble Bytes]
Response)])