#69 ✓resolved
Rusty Klophaus

SimpleBridge Yaws Content Type

Reported by Rusty Klophaus | May 30th, 2010 @ 05:40 PM | in 2.0.1

Investigate this:

Hi Rusty,

I think I found an error in the yaws_response_bridge module of simple
bridge.

the following code

       ContentType = coalesce([
           proplists:get_value(content_type, Res#response.headers),
           proplists:get_value("content-type", Res#response.headers),
           proplists:get_value("Content-Type", Res#response.headers),
           proplists:get_value("CONTENT-TYPE", Res#response.headers),
           "text/html"
       ]),

gives always "text/html" as content type.

I send you a possible correction as attachment.

Best Regards,

Vadim Werbitzky

% Simple Bridge % Copyright (c) 2008-2010 Rusty Klophaus % See MIT-LICENSE for licensing information.

-module(yaws_response_bridge). -behaviour (simple_bridge_response). -include_lib ("yaws_api.hrl"). -include_lib ("simple_bridge.hrl"). -export ([build_response/2]).

build_response(_Arg, Res) ->
% Get vars... Code = Res#response.statuscode, case Res#response.data of

   {data, Body} ->
       % Assemble headers...
       Headers = lists:flatten([
           [{header, {X#header.name, X#header.value}} || X <- Res#response.headers],
           [create_cookie(X) || X <- Res#response.cookies]
       ]),

%======================== NEW CODE: =====================

                   % Get the content type...
                   ContentTypeHeaders =
                           lists:filter(
                                   fun(NextHeaderRecord)->
                                           case NextHeaderRecord of
                                                   _NHR when NextHeaderRecord#header.name =:= content_type;
                                                                     NextHeaderRecord#header.name =:= "content-type";
                                                                     NextHeaderRecord#header.name =:= "Content-Type";
                                                                     NextHeaderRecord#header.name =:= "CONTENT-TYPE" ->
                                                                                   true;
                                                   _ -> false
                                           end
                                   end,
                                   Res#response.headers),
                   ContentType =
                           case ContentTypeHeaders of
                                   [] -> "text/html";
                               [Ct|_] -> Ct#header.value
                           end,

%======================== NEW CODE END ===================== %======================== OLD CODE: =====================

               % Get the content type...
               % ContentType = coalesce([
               %     proplists:get_value(content_type, Res#response.headers),
               %     proplists:get_value("content-type", Res#response.headers),
               %     proplists:get_value("Content-Type", Res#response.headers),
               %     proplists:get_value("CONTENT-TYPE", Res#response.headers),
               %     "text/html"
               % ]),

       % Send the yaws response...
       lists:flatten([
           {status, Code},
           Headers,
           {content, ContentType, Body}
       ]);

   {file, Path} ->
       %% Calculate expire date far into future...
       Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
       TenYears = 10 * 365 * 24 * 60 * 60,
       Seconds1 = calendar:gregorian_seconds_to_datetime(Seconds + TenYears),
       ExpireDate = httpd_util:rfc1123_date(Seconds1),

       % Create the response telling Yaws to server file...
       Options = [{header, {"Expires", ExpireDate}}],
       Path = filename:join(".", Path),
       {page, {Options, Path}}

end.

% NO MORE NEEDED: % coalesce([]) -> undefined; % coalesce([undefined|T]) -> coalesce(T); % coalesce([H|_T]) -> H.

create_cookie(Cookie) ->
Name = Cookie#cookie.name, Value = Cookie#cookie.value, Path = Cookie#cookie.path, SecondsToLive = Cookie#cookie.minutes_to_live * 60, Expire = to_cookie_expire(SecondsToLive), yaws_api:setcookie(Name, Value, Path, Expire).

to_cookie_expire(SecondsToLive) ->
Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()), DateTime = calendar:gregorian_seconds_to_datetime(Seconds + SecondsToLive), httpd_util:rfc1123_date(DateTime).

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Nitrogen Web Framework for Erlang

People watching this ticket

Pages