| Author |
Message |
< Yaws mailing list ~ Getting specific values from hearders (User-Agent, Accept-La |
| hknight |
Posted: Mon Feb 15, 2010 1:10 am |
|
|
|
User
Joined: 07 Jan 2010
Posts: 11
|
How can I get the User-Agent, Accept-Language, and Host from the
headers sent with a request?
My code below places these items in a list but I want to separate them out.
Thanks for the help!
- Hank
----------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
</head>
<body>
<h1> Details about the Request </h1>
<blockquote style="border: 1px solid red; margin: 10px">
<erl>
out(A) ->
Req = A#arg.req,
H = yaws_api:reformat_header(A#arg.headers),
{ehtml,
[{h2,[], "The headers passed to us were:"},
{hr},
{ol, [],lists:map(fun(S) -> {li,[], {p,[],S}} end,H)},
{hr},
{h2, [], "Request Method"},
{pre,[], f("~s", [Req#http_request.method])},
{h2, [], "User-Agent"},
{pre,[], "??? (Should be something like Mozilla/5.0)"},
{h2, [], "Accept-Language"},
{pre,[], "??? (Should be something like en-us,en,en-uk)"},
{h2, [], "Host"},
{pre,[], "??? (Should be something like example.com)"},
{hr},
{h2, [], "Path"},
{pre,[], f("~p", [Req#http_request.path])},
{hr},
{h2, [], "IP Address"},
{pre,[], f("~p", [inet:peername(A#arg.clisock)])},
{hr},
{h2, [], "Parsed GET Query Data"},
{pre,[], f("~p", [yaws_api:parse_query(A)])},
{hr},
{h2,[], "Parsed POST Query data "},
{pre,[], f("~p", [yaws_api:parse_post(A)])}]}.
</erl>
</blockquote>
</body>
</html>
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| hknight |
Posted: Mon Feb 15, 2010 2:08 am |
|
|
|
User
Joined: 07 Jan 2010
Posts: 11
|
Thanks, I tried your code but still can't get it to work.
Is there no easy way with YAWS to get the "User-Agent" for a request?
On Sun, Feb 14, 2010 at 9:34 PM, wde <wde@free.fr> wrote:
> hi,
>
> you can parse the list |
|
|
| Back to top |
|
| Guest |
Posted: Mon Feb 15, 2010 2:19 am |
|
|
|
Guest
|
hi,
you can parse the list (Arg#arg.headers)#headers.other
I use something like that :
find_http_header(Key,Headers) when is_list(Headers) ->
case lists:keysearch(Key,3,Headers) of
{value,{_,_,_,_,Value}} -> Value;
false -> undefined
end.
>How can I get the User-Agent, Accept-Language, and Host from the
>headers sent with a request?
>
>My code below places these items in a list but I want to separate them out.
>
>Thanks for the help!
>
>- Hank
>
>----------------
>
><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
><html xmlns="http://www.w3.org/1999/xhtml">
><head>
><title>Title</title>
></head>
><body>
>
><h1> Details about the Request </h1>
>
><blockquote style="border: 1px solid red; margin: 10px">
>
><erl>
>out(A) ->
>Req = A#arg.req,
>H = yaws_api:reformat_header(A#arg.headers),
>{ehtml,
>[{h2,[], "The headers passed to us were:"},
>{hr},
>{ol, [],lists:map(fun(S) -> {li,[], {p,[],S}} end,H)},
>{hr},
>{h2, [], "Request Method"},
>{pre,[], f("~s", [Req#http_request.method])},
>
>{h2, [], "User-Agent"},
>{pre,[], "??? (Should be something like Mozilla/5.0)"},
>{h2, [], "Accept-Language"},
>{pre,[], "??? (Should be something like en-us,en,en-uk)"},
>{h2, [], "Host"},
>{pre,[], "??? (Should be something like example.com)"},
>
>{hr},
>{h2, [], "Path"},
>{pre,[], f("~p", [Req#http_request.path])},
>{hr},
>{h2, [], "IP Address"},
>{pre,[], f("~p", [inet:peername(A#arg.clisock)])},
>{hr},
>{h2, [], "Parsed GET Query Data"},
>{pre,[], f("~p", [yaws_api:parse_query(A)])},
>{hr},
>{h2,[], "Parsed POST Query data "},
>{pre,[], f("~p", [yaws_api:parse_post(A)])}]}.
></erl>
></blockquote>
>
></body>
></html>
>
>------------------------------------------------------------------------------
>SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
>Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
>http://p.sf.net/sfu/solaris-dev2dev
>_______________________________________________
>Erlyaws-list mailing list
>Erlyaws-list@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/erlyaws-list
>
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Mon Feb 15, 2010 4:21 am |
|
|
|
Guest
|
On Sun, Feb 14, 2010 at 9:08 PM, Hank Knight <hknight555@gmail.com (hknight555@gmail.com)> wrote:
Quote: Thanks, I tried your code but still can't get it to work.
Is there no easy way with YAWS to get the "User-Agent" for a request?
If you're writing a .yaws file, you don't need the following, but otherwise you do:
-include("yaws/include/yaws_api.hrl").
Then, access the User-Agent header via:
(Arg#arg.headers)#headers.user_agent
--steve
Post received from mailinglist |
|
|
| Back to top |
|
| hknight |
Posted: Mon Feb 15, 2010 1:13 pm |
|
|
|
User
Joined: 07 Jan 2010
Posts: 11
|
Thanks, Steve. Your idea works for User-Agent but it doesn't work with
other header values like "Accept-Charset" and "Accept-Language"
----------------------------------------------------------------
<erl>
out(Arg) ->
{status, 200},
{content, "text/html", ""}.
</erl>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Details about the Reuqest</title>
<style type="text/css">
span {color: red;}
h2{font-size: 12pt;}
</style>
</head>
<body>
<h1>Details</h1>
<h2>Your user agent is:
<span>
<erl>
out(A) ->
{html, (A#arg.headers)#headers.user_agent}.
</erl>
</span></h2>
<h2>Host:
<span>
<erl>
out(A) ->
{html, (A#arg.headers)#headers.host}.
</erl>
</span></h2>
<h2>Accept-Language:
<span>
<erl>
out(A) ->
{html, (A#arg.headers)#headers.accept_language}.
</erl>
</span></h2>
<h2>Accept-Charset:
<span>
<erl>
out(A) ->
{html, (A#arg.headers)#headers.accept_charset}.
</erl>
</span></h2>
</body>
</html>
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post received from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Mon Feb 15, 2010 4:10 pm |
|
|
|
Guest
|
On Mon, Feb 15, 2010 at 8:12 AM, Hank Knight <hknight555@gmail.com (hknight555@gmail.com)> wrote:
Quote: Thanks, Steve. Your idea works for User-Agent but it doesn't work with
other header values like "Accept-Charset" and "Accept-Language"
Commonly-used headers appear as fields in the header record, but if it's not in a field, then it's stored in the "other" field. You can find code for interpreting the "other" field in wde's previous response in this thread, and use it like this:
<erl>
out(_) ->
|
|
|
| Back to top |
|
| hknight |
Posted: Mon Feb 15, 2010 10:34 pm |
|
|
|
User
Joined: 07 Jan 2010
Posts: 11
|
|
| Back to top |
|
| wuji |
Posted: Mon Sep 03, 2012 7:14 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
Membership Chair."Instead, Guy said she planned to attend Cornell's program program [h2]imitation designer *beep*[/h2] program in Washington, D.C., in the fall, where she would
in both classes and have an internship, in order to to replica designer *beep* to be close to her home state to fulfill her
Wheatley, director of media relations for Cornell University, said, "That "That [h1]replica designer *beep*[/h1] "That letter was never meant to be public. It was
private letter between her and her sisters. Someone misbehaved in in cheap real jordans in releasing it."Wheatley said she is "staggered" by the involvement
Cornell students, and said their ability to juggle is something something buy real jordans something that they have been doing since they were in
school and continued successfully into college.But it's uncommon for many many [h4]replica designer *beep*[/h4] many state representatives to attend school while fulfilling their duties, |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|