[Zope] Browser sniffing for wireless devices

Tino Wildenhain tino@wildenhain.de
Thu, 03 May 2001 12:10:33 +0200


Hi Chris,

first let me do some shouting: "DONT USE USERAGENT STRING FOR DETECTING
CAPABILITIES" ;)))

This is highly forbidden and very stupid (this is the cause of all
useragents calling themself "Mozilla" ;)

Ok, now we are so far, how do we get the information?

The useragent provides a header called "accept", which gives you
the information what kind of documents it wants. Most developers
use this field appropriate. (There are exceptions like M$ IE, which
sends */* as acceptable mime-type, which is obviously wrong.)

However, every WAP-Device I came accross so far uses text/vnd.wap.wml
and stuff in its accept-header. All other devices are considerably
broken.

The correct implementation would be to negotiate with what you have
(html, wml) and what the user-agent accepts.

This would fail with IE, since it accepts all but cannot render WML,
so you have to treat internally: "if it accepts explicitely wml,
it gets wml, if not, it gets html"

So you only have to scan for */vnd.wap* in the accept-header,
like that:

<dtml-if 
expr="_.string.find(_.string.lower(REQUEST['HTTP_ACCEPT']),'/vnd.wap') >0">
call your wml-producing object here (dont forget to set the appropriate 
mime-type
and watch your encoding)
<dtml-else>
html-rendering here
</dtml-if>

Ok, the best solution would be not using dtml for this :)

HTH
Tino Wildenhain



--On Mittwoch, 2. Mai 2001 19:05 +0000 Chris Muldrow <muldrow@mac.com> 
wrote:

> Anyone doing browser sniffing with Zope to determine whether a user is
> coming in with and HDML or WML-enabled phone? I've got some leads on this,
> but I REALLY don't want to have to check for every USER_AGENT available.
> Is there a good way to check and see A) if it's a WML device B) If not,
> if it's an HDML device C) If it's not, is it an HTML device?
>
> AND another wireless Zope conundrum. I'm serving some HDML pages from
> Zope. When I feed a Content-Type: text/x-hdml with the page, it doesn't
> show up on my Verizon Motorola 2260 phone. When I don't send the
> content-type, it does show up. The opposite is true on the Phone.com SDK
> phone browser--without a content-type, it chokes, but with a content
> type, it works. Any
> enlightenment?
>
> Thankee!
> -- Chris Muldrow, muldrow@mac.com
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )