Apparently there are two ways to set the Content-Type for the ewgi_response():
A - ewgi_api:content_type(CT, Ctx)
B - ewgi_api:response_headers([{"Content-Type",CT}], Ctx)
Problems with that:
- the ewgi_<server> modules all* seem to be iterating over the
headers to read the CT value (set by B method) and ignoring the CT
values that might have been set by method A;
- middleware developers have no way of knowing which method (A or B)
is being used by other middleware.
*I fixed this "bug" in ewgi_yaws (starting using method A) because I
assumed that inets and mochiweb were doing the same thing - and that
it was indeed a bug in yaws' ewgi implementation. Since then I
realized that this is not the case and that even the simple examples
(ewgi_index, ewgi_hello) are setting the CT header in the response
headers.
Given this, which way is the "right way"? :)
Cheers,
Davide :)
Method (A) actually sets the *request* header while method (B) sets
the *response* header. If you are writing middleware that intends to
set the Content-Type header in an HTTP response, you should be using
method (B). Otherwise, you are simply setting a request header for
downstream applications.
Does that clear things up?
> *I fixed this "bug" in ewgi_yaws (starting using method A) because I
> assumed that inets and mochiweb were doing the same thing - and that
> it was indeed a bug in yaws' ewgi implementation. Since then I
> realized that this is not the case and that even the simple examples
> (ewgi_index, ewgi_hello) are setting the CT header in the response
> headers.
I will take a look at your changes. I'll take a look at the fork
queue on github and pull in your bug fixes as well.
Thanks again for your contributions!
~Hunter
On Sat, Sep 19, 2009 at 1:48 PM, Hunter Morris <hunter...@gmail.com> wrote:
>> Apparently there are two ways to set the Content-Type for the ewgi_response():
>> A - ewgi_api:content_type(CT, Ctx)
>> B - ewgi_api:response_headers([{"Content-Type",CT}], Ctx)
>
> Method (A) actually sets the *request* header while method (B) sets
> the *response* header. If you are writing middleware that intends to
> set the Content-Type header in an HTTP response, you should be using
> method (B). Otherwise, you are simply setting a request header for
> downstream applications.
>
> Does that clear things up?
Completely. Thanks! :)
> I will take a look at your changes. I'll take a look at the fork
> queue on github and pull in your bug fixes as well.
I've rolled back the ewgi_yaws "fix" so it should be correct again.
While testing the examples I noticed that the content-type of the inets server
defaults to "text/html" while in the others it defaults to
"text/plain" (this can
be seen on the ewgi_session example because I forgot to set the CT headers).
Does this need fixing?
Another thing: the ewgi_stream_file example is failing in the most recent
yaws version - a patch is on its way to the main repo.
> Thanks again for your contributions!
Don't mention it. Standing on the shoulders of giants here. :)
Cheers,
Davide :)