Skip to content

Commit

Permalink
explicit support for content_length
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@627 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Mar 11, 2004
1 parent dc00e52 commit e2f272a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
49 changes: 46 additions & 3 deletions man/yaws_api.5
Expand Up @@ -5,7 +5,7 @@ yaws_api \- api available to yaws web server programmers
.B yaws_api:Function(...)

.SH DESCRIPTION
.\" Add any additional description here

.PP
This is the api available to yaws web server programmers. The erlang
module yaws_api contains a wide variety of functions that can
Expand Down Expand Up @@ -414,14 +414,57 @@ html parts at all.
\fB{streamcontent, MimeType, FirstChunk}\fR
This return value plays the same role as the \fIcontent\fR return
value above.

However it makes it possible to stream data to the client
if the yaws code doesn't have access to all the data in one go. (Typically
if a file is very large or if data arrives from back end servers on the network.

.TP
\fB{header, H}\fR
Accumulates a HTTP header. Used by for example the \fBsetcookie/2-6\fR
function.
Accumulates a HTTP header. The trailing CRNL which is supposed
to end all HTTp headers must not be added. It is added by the server.
The following list of headers are given special treatment.

\fI{connection, What}\fR

This sets the connection header. If \fIWhat\fR is the special value
\fI"close"\fR, the connection will be closed once the yaws page is delivered
to the client.

\fI{location, Url}\fR

Sets the Location: header. This header is typically combined with
the \fI{status, 302}\fR return value.

\fI{cache_control, What}\fR

Sets the Cache-Control: header.

\fI{set_cookie, Cookie}\fR

Prepends a a Set-Cookie: header to the list of previousy
set Set-Cookie: headers.

\fI{content_type, MimeType}\fR

Sets the Content-Type header.

\fI{content_length, Len}\fR

Normally yaws will ship Yaws pages using Transfer-Encoding: chunked. This
is because we generally can't know how long a yaws page will be. If we for
some reason want to force a Content-Length: header (and we actually do
know the length of the content, we can force yaws to not ship the
page chunked.


All other headers must be added using the normal HTTP syntax.
Example:

{header, "My-X-Header: gadong"}




.TP
\fB{allheaders, HeaderList}\fB
Expand Down
7 changes: 7 additions & 0 deletions src/yaws.erl
Expand Up @@ -1380,6 +1380,13 @@ accumulate_header({set_cookie, What}) ->
accumulate_header({content_type, What}) ->
put(outh, (get(outh))#outh{content_type = ["Content-Type: " , What, "\r\n"]});

accumulate_header({content_length, Len}) when integer(Len) ->
H = get(outh),
put(outh, H#outh{
chunked = false,
transfer_encoding = undefined,
content_length = make_content_length_header(Len)});


%% backwards compatible clause
accumulate_header(Str) when list(Str) ->
Expand Down
21 changes: 2 additions & 19 deletions src/yaws_api.erl
Expand Up @@ -902,23 +902,8 @@ lmap(_, []) ->

%% interactively turn on|off tracing
set_trace(Val) ->
case lists:member(Val, [traffic, http, false]) of
true ->
{ok, GC, Groups} = getconf(),
Tval = case Val of
http ->
{true, http};
traffic ->
{true, traffic};
false ->
false
end,
setconf(GC#gconf{trace = Tval}, Groups);
_ ->
io:format(
"Usage: set_trace(true | false, traffic | http | access)",[])
end.

Str = yaws_ctl:actl_trace(Val),
io:format("~s", [Str]).


set_access_log(Bool) ->
Expand All @@ -929,8 +914,6 @@ set_access_log(Bool) ->
setconf(GC, Groups2).




%% interactively turn on|off tracing to the tty (as well)
%% typically useful in embedded mode
set_tty_trace(Bool) ->
Expand Down

0 comments on commit e2f272a

Please sign in to comment.