Skip to content

Commit d9b8fe5

Browse files
soraweejeapostrophe
authored andcommitted
add documentation and bump version
1 parent 80d1f58 commit d9b8fe5

File tree

2 files changed

+71
-18
lines changed

2 files changed

+71
-18
lines changed

web-server-doc/web-server/scribblings/dispatchers.scrbl

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,29 +195,30 @@ This is used in the standard @web-server pipeline to provide
195195
a URL that refreshes the password file, servlet cache, etc.}
196196

197197
@; ------------------------------------------------------------
198-
@section[#:tag "dispatch-log"]{Logging}
199-
@a-dispatcher[web-server/dispatchers/dispatch-log
198+
@section[#:tag "dispatch-logresp"]{Logging}
199+
@a-dispatcher[web-server/dispatchers/dispatch-logresp
200200
@elem{defines a dispatcher constructor
201-
for transparent logging of requests.}]{
201+
for transparent logging of requests and responses.}]{
202202

203-
@defthing[format-req/c contract?]{
204-
Equivalent to @racket[(request? . -> . string?)].
203+
@defthing[format-reqresp/c contract?]{
204+
Equivalent to @racket[(or/c (request? . -> . string?) (request? response? . -> . string?))].
205205
}
206206

207-
@defthing[paren-format format-req/c]{
208-
Formats a request by:
207+
@defthing[paren-format format-reqresp/c]{
208+
Formats a request and a response by:
209209
@racketblock[
210210
(format
211211
"~s\n"
212212
(list 'from (request-client-ip req)
213213
'to (request-host-ip req)
214-
'for (url->string (request-uri req)) 'at
215-
(date->string
216-
(seconds->date (current-seconds)) #t)))
214+
'for (url->string (request-uri req))
215+
'at (date->string
216+
(seconds->date (current-seconds)) #t)
217+
'code (response-code resp)))
217218
]}
218219

219-
@defthing[extended-format format-req/c]{
220-
Formats a request by:
220+
@defthing[extended-format format-reqresp/c]{
221+
Formats a request and a response by:
221222
@racketblock[
222223
(format
223224
"~s\n"
@@ -231,15 +232,66 @@ a URL that refreshes the password file, servlet cache, etc.}
231232
(header-value R)
232233
#f)))
233234
(uri ,(url->string (request-uri req)))
234-
(time ,(current-seconds))))
235+
(time ,(current-seconds))
236+
(code ,(response-code resp))))
235237
]}
236238

237-
@defthing[apache-default-format format-req/c]{
239+
@defthing[apache-default-format format-reqresp/c]{
240+
Formats a request and a response like Apache's default. However, Apache's default
241+
includes information about the size of the object returned to the client,
242+
which this function does not have access to, so it defaults the last field
243+
to @litchar{-}.
244+
}
245+
246+
@defthing[log-format/c contract?]{
247+
Equivalent to @racket[(symbols 'parenthesized-default 'extended 'apache-default)].
248+
}
249+
250+
@defproc[(log-format->format [id log-format/c])
251+
format-reqresp/c]{
252+
Maps @racket['parenthesized-default] to @racket[paren-format],
253+
@racket['extended] to @racket[extended-format], and
254+
@racket['apache-default] to @racket[apache-default-format].
255+
}
238256

257+
@defproc[(make [#:format format (or/c log-format/c format-reqresp/c) paren-format]
258+
[#:log-path log-path (or/c path-string? output-port?) "log"]
259+
[dispatcher dispatcher/c])
260+
dispatcher/c]{
261+
If @racket[dispatcher] is successfully dispatched,
262+
logs requests and responses (without the @racket[body] information)
263+
to @racket[log-path], which can be either a filepath or an @racket[output-port?],
264+
using @racket[format] to format the requests and responses
265+
(or just requests if @racket[format] only accepts one argument).
266+
If @racket[format] is a symbol, a log formatter will be tacitly made using @racket[log-format->format].
267+
268+
@history[#:added "1.12"]
269+
}}
270+
271+
@; ------------------------------------------------------------
272+
@section[#:tag "dispatch-log"]{Basic Logging}
273+
@a-dispatcher[web-server/dispatchers/dispatch-log
274+
@elem{defines a dispatcher constructor
275+
for transparent logging of requests.
276+
Consider using the facilities in
277+
@secref{dispatch-logresp} instead,
278+
as it provides more flexibility.}]{
279+
280+
@defthing[format-req/c contract?]{
281+
Equivalent to @racket[(request? . -> . string?)].
282+
}
283+
284+
@defthing[paren-format format-req/c]{
285+
Formats a request like its counterpart in @secref{dispatch-logresp}, but without the response code information.}
286+
287+
@defthing[extended-format format-req/c]{
288+
Formats a request like its counterpart in @secref{dispatch-logresp}, but without the response code information.}
289+
290+
@defthing[apache-default-format format-req/c]{
239291
Formats a request like Apache's default. However, Apache's default
240292
includes information about the response to a request, which this
241293
function does not have access to, so it defaults the last two fields
242-
to @racket[200] and @racket[512].
294+
to @litchar{-} and @litchar{-}.
243295

244296
}
245297

@@ -258,8 +310,9 @@ a URL that refreshes the password file, servlet cache, etc.}
258310
[#:log-path log-path (or/c path-string? output-port?) "log"])
259311
dispatcher/c]{
260312
Logs requests to @racket[log-path], which can be either a filepath or an @racket[output-port?],
261-
using @racket[format] to format the requests. (If @racket[format] is a symbol, a log formatter
262-
will be tacitly made using @racket[log-format->format].)
313+
using @racket[format] to format the requests.
314+
If @racket[format] is a symbol,
315+
a log formatter will be tacitly made using @racket[log-format->format].
263316
Then invokes @racket[next-dispatcher].
264317

265318
@history[

web-server-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
(define pkg-authors '(jay))
1616

17-
(define version "1.11")
17+
(define version "1.12")
1818

1919
(define license
2020
'(Apache-2.0 OR MIT))

0 commit comments

Comments
 (0)