Mercurial > urweb
comparison doc/manual.tex @ 1465:2f5fd248588d
getHeader and setHeader
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 29 May 2011 14:29:26 -0400 |
parents | 969b90b1f2f9 |
children | a354b306f948 |
comparison
equal
deleted
inserted
replaced
1464:969b90b1f2f9 | 1465:2f5fd248588d |
---|---|
134 | 134 |
135 For each entry \texttt{M} in the module list, the file \texttt{M.urs} is included in the project if it exists, and the file \texttt{M.ur} must exist and is always included. | 135 For each entry \texttt{M} in the module list, the file \texttt{M.urs} is included in the project if it exists, and the file \texttt{M.ur} must exist and is always included. |
136 | 136 |
137 Here is the complete list of directive forms. ``FFI'' stands for ``foreign function interface,'' Ur's facility for interaction between Ur programs and C and JavaScript libraries. | 137 Here is the complete list of directive forms. ``FFI'' stands for ``foreign function interface,'' Ur's facility for interaction between Ur programs and C and JavaScript libraries. |
138 \begin{itemize} | 138 \begin{itemize} |
139 \item \texttt{[allow|deny] [url|mime] PATTERN} registers a rule governing which URLs or MIME types are allowed in this application. The first such rule to match a URL or MIME type determines the verdict. If \texttt{PATTERN} ends in \texttt{*}, it is interpreted as a prefix rule. Otherwise, a string must match it exactly. | 139 \item \texttt{[allow|deny] [url|mime|requestHeader|responseHeader] PATTERN} registers a rule governing which URLs, MIME types, HTTP request headers, or HTTP response headers are allowed to appear explicitly in this application. The first such rule to match a name determines the verdict. If \texttt{PATTERN} ends in \texttt{*}, it is interpreted as a prefix rule. Otherwise, a string must match it exactly. |
140 \item \texttt{alwaysInline PATH} requests that every call to the referenced function be inlined. Section \ref{structure} explains how functions are assigned path strings. | 140 \item \texttt{alwaysInline PATH} requests that every call to the referenced function be inlined. Section \ref{structure} explains how functions are assigned path strings. |
141 \item \texttt{benignEffectful Module.ident} registers an FFI function or transaction as having side effects. The optimizer avoids removing, moving, or duplicating calls to such functions. Every effectful FFI function must be registered, or the optimizer may make invalid transformations. This version of the \texttt{effectful} directive registers that this function only has side effects that remain local to a single page generation. | 141 \item \texttt{benignEffectful Module.ident} registers an FFI function or transaction as having side effects. The optimizer avoids removing, moving, or duplicating calls to such functions. Every effectful FFI function must be registered, or the optimizer may make invalid transformations. This version of the \texttt{effectful} directive registers that this function only has side effects that remain local to a single page generation. |
142 \item \texttt{clientOnly Module.ident} registers an FFI function or transaction that may only be run in client browsers. | 142 \item \texttt{clientOnly Module.ident} registers an FFI function or transaction that may only be run in client browsers. |
143 \item \texttt{clientToServer Module.ident} adds FFI type \texttt{Module.ident} to the list of types that are OK to marshal from clients to servers. Values like XML trees and SQL queries are hard to marshal without introducing expensive validity checks, so it's easier to ensure that the server never trusts clients to send such values. The file \texttt{include/urweb.h} shows examples of the C support functions that are required of any type that may be marshalled. These include \texttt{attrify}, \texttt{urlify}, and \texttt{unurlify} functions. | 143 \item \texttt{clientToServer Module.ident} adds FFI type \texttt{Module.ident} to the list of types that are OK to marshal from clients to servers. Values like XML trees and SQL queries are hard to marshal without introducing expensive validity checks, so it's easier to ensure that the server never trusts clients to send such values. The file \texttt{include/urweb.h} shows examples of the C support functions that are required of any type that may be marshalled. These include \texttt{attrify}, \texttt{urlify}, and \texttt{unurlify} functions. |
144 \item \texttt{database DBSTRING} sets the string to pass to libpq to open a database connection. | 144 \item \texttt{database DBSTRING} sets the string to pass to libpq to open a database connection. |
1404 \mt{val} \; \mt{fileName} : \mt{file} \to \mt{option} \; \mt{string} \\ | 1404 \mt{val} \; \mt{fileName} : \mt{file} \to \mt{option} \; \mt{string} \\ |
1405 \mt{val} \; \mt{fileMimeType} : \mt{file} \to \mt{string} \\ | 1405 \mt{val} \; \mt{fileMimeType} : \mt{file} \to \mt{string} \\ |
1406 \mt{val} \; \mt{fileData} : \mt{file} \to \mt{blob} | 1406 \mt{val} \; \mt{fileData} : \mt{file} \to \mt{blob} |
1407 \end{array}$$ | 1407 \end{array}$$ |
1408 | 1408 |
1409 It is also possible to get HTTP request headers and set HTTP response headers, using abstract types similar to the one for URLs. | |
1410 | |
1411 $$\begin{array}{l} | |
1412 \mt{type} \; \mt{requestHeader} \\ | |
1413 \mt{val} \; \mt{blessRequestHeader} : \mt{string} \to \mt{requestHeader} \\ | |
1414 \mt{val} \; \mt{checkRequestHeader} : \mt{string} \to \mt{option} \; \mt{requestHeader} \\ | |
1415 \mt{val} \; \mt{getHeader} : \mt{requestHeader} \to \mt{transaction} \; (\mt{option} \; \mt{string}) \\ | |
1416 \\ | |
1417 \mt{type} \; \mt{responseHeader} \\ | |
1418 \mt{val} \; \mt{blessResponseHeader} : \mt{string} \to \mt{responseHeader} \\ | |
1419 \mt{val} \; \mt{checkResponseHeader} : \mt{string} \to \mt{option} \; \mt{responseHeader} \\ | |
1420 \mt{val} \; \mt{setHeader} : \mt{responseHeader} \to \mt{string} \to \mt{transaction} \; \mt{unit} | |
1421 \end{array}$$ | |
1422 | |
1409 A blob can be extracted from a file and returned as the page result. There are bless and check functions for MIME types analogous to those for URLs. | 1423 A blob can be extracted from a file and returned as the page result. There are bless and check functions for MIME types analogous to those for URLs. |
1410 $$\begin{array}{l} | 1424 $$\begin{array}{l} |
1411 \mt{type} \; \mt{mimeType} \\ | 1425 \mt{type} \; \mt{mimeType} \\ |
1412 \mt{val} \; \mt{blessMime} : \mt{string} \to \mt{mimeType} \\ | 1426 \mt{val} \; \mt{blessMime} : \mt{string} \to \mt{mimeType} \\ |
1413 \mt{val} \; \mt{checkMime} : \mt{string} \to \mt{option} \; \mt{mimeType} \\ | 1427 \mt{val} \; \mt{checkMime} : \mt{string} \to \mt{option} \; \mt{mimeType} \\ |