Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set text/html instead of text/plain? #59

Closed
radetsky opened this issue Apr 4, 2014 · 11 comments
Closed

How to set text/html instead of text/plain? #59

radetsky opened this issue Apr 4, 2014 · 11 comments

Comments

@radetsky
Copy link

radetsky commented Apr 4, 2014

Version: HEAD.
DTL: 0.8.0
I created new another template. It's rendered normally. But something set text/plain mime type. What do I wrong ?

@radetsky radetsky changed the title Mime type broken. Text/plain. Mime type broken. Text/plain. Apr 4, 2014
@doxtop
Copy link
Contributor

doxtop commented Apr 4, 2014

mime types are not related to dtl and templates i think.
check you mimetypes application running, check the cowboy dispatch rules configuration...
need more info about what you are trying to do to know what is wrong :)

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Originally it was your example/template of n2o-application named 'skyline'.
For example let's take a look on login page.
main() ->
[#dtl{file="login", ext="dtl", bindings=[
{title,<<"My Title">>},
{form, form()},
{body, body()}
]}
].

If I use your prod.dtl as template all works fine. If I set newly created login.dtl mime type is broken. I did not any changes to cowboy dispatch rules and I do not know where is it.

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Ok, I find in web_sup.erl dispatch_rules() but I did not change it.
dispatch_rules() ->
cowboy_router:compile(
[{'', [
{"/static/[...]", cowboy_static, [{directory, {priv_dir, ?APP, [<<"static">>]}},
{mimetypes, {fun mimetypes:path_to_mimes/2, default}}]},
{"/rest/:bucket", n2o_rest, []},
{"/rest/:bucket/:key", n2o_rest, []},
{"/rest/:bucket/:key/[...]", n2o_rest, []},
{"/ws/[...]", bullet_handler, [{handler, n2o_bullet}]},
{'
', n2o_cowboy, []}
]}]).

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Если я пропатчу wf_core:run() вот так:

Req2 = wf:response(Html,Ctx2#context.req),
Req3 = wf:header(<<"Content-Type">>,<<"text/html; charset=utf-8">>,Req2),
{ok, _ReqFinal} = wf:reply(200, Req3).

То, mime насильно устанавливается в text/html, то переменная transition не появляется в рамках выполнения js в броузере.

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Нашел в полученной странице следующий код:

var transition = {pid: 'g2gCZ2QAEXNreWxpbmVAMTI3LjAuMC4xAAAFPQAAAAABaANiAAAFdGIACWrzYgAEt9s=', port:'8000'} Одной проблемой меньше, но mime кроме грязного хака я не знаю как починить. :(

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Я не наблюдаю установку mime type.

Request URL:http://localhost:8000/
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:CGISESSID=d7576982f0032b7951a886f5ed09880f; n2o-sid=+ikgHbIPalYudCMZrH1Leg==
Host:localhost:8000
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36

Response Headers
HTTP/1.1 200 OK
connection: keep-alive
server: Cowboy
date: Fri, 04 Apr 2014 14:59:28 GMT
content-length: 6390
set-cookie: n2o-sid=+ikgHbIPalYudCMZrH1Leg==; Version=1; Expires=Sat, 05-Apr-2014 14:59:29 GMT; Max-Age=86400; Path=/

И еще: заменил login.dtl на prod.dtl и mime заработал.
А если в prod.dtl поменять содержимое на login.dtl, то mime опять ломается.
Вывод, какая-то привязка к чему-то в самом тексте шаблона.

@doxtop
Copy link
Contributor

doxtop commented Apr 4, 2014

проверил у себя, все таки оно автоматически определяет mime type, все что это внутри < html >< /html > должно быть text\html автоматически.
как это все натюнить, смотри в настройках приложения mimetypes и провайдь конфигурацию, там настроек на все случаи жизни.

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Можешь показать свой конфиг ?

@doxtop
Copy link
Contributor

doxtop commented Apr 4, 2014

у меня девалтный конфиг. твой новый шаблон содержит html? можешь дать мне этот шаблон?

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Улетело почтой.

@radetsky
Copy link
Author

radetsky commented Apr 4, 2014

Н-да. Причина оказалась в BOM:
The byte order mark (BOM) is a Unicode character used to signal the endianness (byte order) of a text file or stream. It is encoded at U+FEFF byte order mark (BOM). BOM use is optional, and, if used, should appear at the start of the text stream.

Куда наливать ?

@radetsky radetsky closed this as completed Apr 4, 2014
@5HT 5HT changed the title Mime type broken. Text/plain. How to set text/html instead of text/plain? Apr 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants