#lang scheme/base
(require mzlib/trace
scheme/contract
net/url
web-server/http/request-structs
)
(define $pathinfo (make-parameter '()))
(define $request (make-parameter #f))
(define ($uri)
(request-uri ($request)))
(define ($header key)
(headers-assq* (string->bytes/utf-8 key) (request-headers/raw ($request))))
(define ($query* key)
(define (helper bindings)
(map (lambda (b)
(if (binding:form? b)
(bytes->string/utf-8 (binding:form-value b))
b))
bindings))
(helper (filter (lambda (binding)
(string-ci=? (bytes->string/utf-8 (binding-id binding))
key))
(request-bindings/raw ($request)))))
(define ($query key)
(let ((vals ($query* key)))
(if (null? vals) #f
(car vals))))
(provide/contract
($pathinfo (parameter/c (listof string?)))
($request (parameter/c request?))
($uri (-> url?))
($header (-> string? (or/c #f bytes? string?)))
($query (-> string? (or/c #f bytes? binding?)))
($query* (-> string? (listof (or/c bytes? binding?))))
)