{"size": 2051, "ext": "scrbl", "max_stars_repo_path": "web-server-doc/web-server/scribblings/contracts.scrbl", "max_stars_repo_name": "jessealama/web-server", "max_stars_repo_stars_event_min_datetime": "2015-01-21T08:11:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T08:28:39.000Z", "max_issues_repo_path": "web-server-doc/web-server/scribblings/contracts.scrbl", "max_issues_repo_name": "jessealama/web-server", "max_issues_repo_issues_event_min_datetime": "2015-01-14T08:06:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T14:38:40.000Z", "max_forks_repo_path": "web-server-doc/web-server/scribblings/contracts.scrbl", "max_forks_repo_name": "jessealama/web-server", "max_forks_repo_forks_event_min_datetime": "2015-03-05T15:07:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T18:59:25.000Z"}
{"max_stars_count": 82, "max_issues_count": 105, "max_forks_count": 37, "avg_line_length": 46.6136363636, "max_line_length": 123, "alphanum_fraction": 0.7162359824}
#lang scribble/doc
@(require "web-server.rkt")

@title[#:tag "servlet-structs"]{Responses}
@(require (for-label web-server/servlet/servlet-structs
                     web-server/http
                     web-server/servlet))

@defmodule[web-server/servlet/servlet-structs]{

Servlets communicate to the Web Server by returning HTTP responses. In order to
accommodate lightweight programs (and backwards compatibility), the Web Server
provides an indirection from application-specific response formats and the internal
HTTP response format, @racket[response].

@deftogether[[
@defproc[(can-be-response? [x any/c])
          boolean?]
@defproc[(any->response [x any/c])
         (or/c false/c response?)]
@defproc[(set-any->response! [new-any->response (-> any/c (or/c false/c response?))])
         void]
]]{

   @racket[any->response] coerces any value into a response or returns @racket[#f] if coercion is not possible.
   @racket[any->response] guarantees that any @racket[response?] input must always be returned exactly (i.e. @racket[eq?].)
   The default always returns @racket[#f], signifying that no coercion is possible.
   
   @racket[can-be-response?] returns @racket[#t] if @racket[x] is a response or can be turned into a response by calling
   @racket[any->response].
   
   Users of @racket[any->response] should protect themselves by using @racket[can-be-response?] as a contract.
   If they do so, they can safely ignore the @racket[#f] return case of @racket[any->response].
   
   @racket[set-any->response!] replaces the global @racket[any->response] with the supplied argument. This
   function should return the same value for @racket[eq?] inputs to ensure that @racket[can-be-response?] is
   any accurate predicate. Similarly, this function should be cheap to call multiple times on the same input,
   since it will be used in contract checking as well as coercion before transmission. You may want to use a
   weak @racket[eq?]-based hash-table to cache the results for this purpose. (See @racket[make-weak-hasheq].)
   
}

}
