Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

explicit support for content_length

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@627 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit e2f272a37c0a07f8c0c096598173da47f8656a96 1 parent dc00e52
@klacke authored
Showing with 55 additions and 22 deletions.
  1. +46 −3 man/yaws_api.5
  2. +7 −0 src/yaws.erl
  3. +2 −19 src/yaws_api.erl
View
49 man/yaws_api.5
@@ -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
@@ -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
View
7 src/yaws.erl
@@ -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) ->
View
21 src/yaws_api.erl
@@ -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) ->
@@ -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) ->
Please sign in to comment.
Something went wrong with that request. Please try again.