Content Negotiation for Safari 4. Any way to override?

2009-06-24 Thread Bruce Cooper
Hi guys,

I'm setting up a restlet app at the moment, and I'd like to set it up so that 
if a user uses a browser to access a resource, he gets given a nicely formatted 
HTML page, but if he separately asks for XML or JSON he gets a machine parsable 
response.  Its all working well on Firefox, but I'm having some issues getting 
it working on Safari 4.

It looks like the problem is the Accept: header that is being sent in by 
Safari.  Its 

application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

This causes the content negotiation process to favor xml as an output over 
html, as html has a priority of 0.9.  I tried xhtml, which has the same 
priority as xml, but it looks like it still chooses xml (presumably it is 
random which response you get if they have the same priority).

Is there a way I can override Safari's preferences?  I know that it is asking 
to have xml as the highest priority, but frankly I think that is wrong.

Any suggestions that you can give would be appreciated.

Bruce.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2364881


Re: Content Negotiation for Safari 4. Any way to override?

2009-06-25 Thread Bruce Cooper
Hi guys,

I have found that the agentName is reporting as Safari with a capitol S
whereas the standard file has it listed with a lowercase s, so I've needed
to add a separate rule in accept.properties.  Because I want to only
override the default Accept that is being sent through (and so that I can
put in other accepts in XMLHttpRequest requests and not have them
overridden)*, I think it is best to include the acceptOld as shown below:*

#Safari
agentName: Safari
acceptOld:
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
acceptNew: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

This appears to work for me, so I'm happy.  Let me know if you think it is a
good solution.

Bruce.


--
www.brucecooper.net - 0417 986 274


2009/6/25 Thierry Boileau 

> Hello Bruno,
> could you try by removing the "acceptOld" line? It is not mandatory.
>
> best regards,
> Thierry Boileau
>
> > Hi Thierry,
> >
> > I'm not entirely sure what the intended behaviour of the TunnelService
> > (regarding user-agents) is. Could you confirm this should be as follow
> > (assuming the user agent tunnel is switched on in the service)?
> >
> >
> > Step 1. The TunnelService parses the 'User-Agent' header and compares it
> > to "org/restlet/data/agent.properties", therefore populating agent
> > attributes in the client info class.
> >
> > For example (with Safari 4):
> > User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us)
> > AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18
> >
> > ->
> > {agentOsShortName=Macintosh, osData= en-us, agentName=Safari,
> > mozillaVersion=5.0, appleWebKitComment=KHTML, like Gecko,
> > familyVersion=4.0.1, agentVersion=530.18, agentOs=Intel Mac OS X 10_5_7,
> > appleWebKitVersion=530.18}
> >
> > Step 2. The service then looks into
> > "org/restlet/service/accept.properties", if the 'agentName' (in a given
> > block in this file) matches the 'agentName' in the agent attributes and
> > if the 'acceptOld' line (in the same block) matches the original
> > 'Accept' header in the request, then 'Accept' is replaced with the value
> > in 'acceptNew'.
> >
> >
> >
> > In the test above, the agentName is detected properly, but it seems the
> > blank line in the acceptOld config file doesn't mean it's a wildcard, so
> > there should probably be the actual Accept header sent by Safari in this
> > configuration file. This may be the reason why it doesn't work (it seems
> > to work when that line is configured to match the Accept header sent).
> >
> >
> > Best wishes,
> >
> > Bruno.
> >
> >
> >
> > P.S.: Below are a few User-Agent and Accept headers I've been able to
> > gather.
> >
> > - Firefox 2 on XP:
> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.20)
> > Gecko/20081217 Firefox/2.0.0.20 (.NET CLR 3.5.30729)
> > Accept:
> >
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > (I was surprised to see that this one doesn't seem to be recognised as
> > 'agentName=Firefox' but 'Mozilla'; here are the attributes:
> > {agentName=Mozilla, osData=Windows NT 5.1; en-GB; rv:1.8.1.20)
> > Gecko/20081217 Firefox/2.0.0.20 (.NET CLR 3.5.30729, agentVersion=5.0,
> > agentOs=Windows}.)
> >
> >
> > - Browser in the GWT Eclipse plugin:
> > User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.12)
> > Gecko/20050920
> > Accept:
> >
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > - iPod Touch (FW 2.2.1, not the latest):
> > User-Agent: Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2_1 like Mac OS X;
> > en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1
> > Mobile/5H11 Safari/525.20
> > Accept:
> >
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > - MSIE 8 on XP:
> > Accept: */*
> > User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
> > Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR
> > 3.0.4506.2152; .NET CLR 3.5.30729)
> >
> > - Safari 4 on XP:
> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
> > AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17
> > Accept:
> >
> application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > - Safari 4 on OSX:
> > User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us)
> > AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18
> > Accept:
> >
> application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > Thierry Boileau wrote:
> >
> >> Hi Bruce,
> >>
> >> can you send us the content of the "user-agent" header? We will complete
> >> the default "agent.properties" file.
> >>
> >> best regards,
> >> Thierry Boileau
> >>
> >>> Hi guys,
> >>>
> >>> I'm setting up a restlet app at the moment, and I'd like to set it up
> so that if a user uses

Re: Content Negotiation for Safari 4. Any way to override?

2009-06-25 Thread Bruce Cooper
Hi Thierry,
As Bruno said, the user agent is:


   1. Accept:

   
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
   2. User-Agent:
   Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-au)
   AppleWebKit/530.18 (KHTML, like Gecko) Version/4.0.1 Safari/530.18


Which is exactly the same as Safari 3 as far as I am aware, apart from
version numbers.  Thanks for the links, I'll look into it now.

Bruce.


--
www.brucecooper.net - 0417 986 274


2009/6/24 Thierry Boileau 

> Hello Bruce,
>
> could you have a look at this page [1] of the user guide? And at the
> javadocs of the tunnelService class [2], and ClientInfo class [3].
> The solution is based on two properties files.
> One (agent.properties), helps to match the user-agent string (sent by
> the browser) and extract some information such as the agent name
> (Safari, for example). Some browsers have been identified (especially
> Safari 2 and 3).
> The other one is called accept.properties, and helps to override the
> accept header of a browser.
> If you want to activate this mechanism, turn on the "UserAgentTunnel"
> attribute of the Application#tunnelService.
>
>
> best regards,
> Thierry Boileau
> [1] http://wiki.restlet.org/docs_1.2/207-restlet.html
> [2]
>
> http://www.restlet.org/documentation/2.0/api/org/restlet/service/TunnelService.html
> [3]
>
> http://www.restlet.org/documentation/1.1/api/org/restlet/data/ClientInfo.html#getAgentAttributes()
>
>
> > Hi guys,
> >
> > I'm setting up a restlet app at the moment, and I'd like to set it up so
> that if a user uses a browser to access a resource, he gets given a nicely
> formatted HTML page, but if he separately asks for XML or JSON he gets a
> machine parsable response.  Its all working well on Firefox, but I'm having
> some issues getting it working on Safari 4.
> >
> > It looks like the problem is the Accept: header that is being sent in by
> Safari.  Its
> >
> >
> application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >
> > This causes the content negotiation process to favor xml as an output
> over html, as html has a priority of 0.9.  I tried xhtml, which has the same
> priority as xml, but it looks like it still chooses xml (presumably it is
> random which response you get if they have the same priority).
> >
> > Is there a way I can override Safari's preferences?  I know that it is
> asking to have xml as the highest priority, but frankly I think that is
> wrong.
> >
> > Any suggestions that you can give would be appreciated.
> >
> > Bruce.
> >
> > --
> >
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2364881
> >
> >
>
> --
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2364926
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2365190

Re: Issues loading css files (from a Directory) using Firefox

2009-07-11 Thread Bruce Cooper
Hi Jerome,
I tried the suggestion of changing the default charset in the application,
and that has resolved the issue for me.  Its probably still worthwhile
registering this as an issue on Mac, even though there is a workaround.
 I'll leave it as a TODO in my application, just in case nobody else gets
around to looking at it.

Thanks very much for your help,

Bruce.
--
www.brucecooper.net - 0417 986 274 - www.unico.com.au


2009/7/5 Jerome Louvel 

>  Hi Bruce,
>
>
>
> That’s rather unexpected indeed. I’ve checked the text/css media type and
> it does support the charset parameter:
>
> http://tools.ietf.org/html/rfc2318
>
>
>
> What seems wrong is the name of the character set. Looking at IANA
> registry, the proper name is either “macintosh” or “mac”, but not
> “MACROMAN”:
>
> http://en.wikipedia.org/wiki/Mac_OS_Roman
>
> http://www.iana.org/assignments/character-sets
>
>
>
> A test that would be interesting to do is to change the default character
> set to something like UTF-8 to see if this is the value of the character set
> that annoys FireFox. One way to do this is:
>
>
>
> myApp.getMetadataService().setDefaultCharacterSet(CharacterSet.UTF_8);
>
>
>
> BTW, I’ve also added CharacterSet.MACINTOSH constant and default extension
> mappings for character sets in MetadataService (“ascii”, “utf8”, “utf16”,
> “mac”, “win”).
>
>
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>
>
>
>
>
>
>
> *De :* Bruce Cooper [mailto:br...@brucecooper.net]
> *Envoyé :* dimanche 28 juin 2009 10:38
> *À :* discuss@restlet.tigris.org
> *Objet :* Issues loading css files (from a Directory) using Firefox
>
>
>
> Hi guys,
>
>
>
> I've been using a Directory object to serve up the user interface of my
> REST style application, and that application consists of HTML, javascript
> and CSS.  I've found today that Firefox 3.5 on my Mac was not reading CSS
> files correctly.  To be more specific, it was reading the files, but was not
> using the results that were returned.
>
>
>
> To work out what was going wrong, I wrote a simple test page, which had a
> single DIV with a background color set by a style in an attached style
> sheet.  Viewing the page directly from the disk using Safari or Firefox
> worked.  Viewing the Page when served by Apache worked for both Safari and
> Firefox.  When the files were served up by the restlet engine, it continued
> to work correctly in Safari, but Firefox ignored the stylesheet.  After
> this, I spent a bit of time in Firebug having a look in headers. The main
> difference I could see was that the restlet engine was reporting the
> content-type of the repsonse as
>
>
>
> text/css; charset=MACROMAN
>
>
>
> Whereas Apache was just returning the content type as text/css.
>
>
>
> I've dug around the code and found that in org.restlet.engine.local.Entity
> line 252 it sets the charset of the response to the platform default if it
> hasn't already been set.  To test my theory, I commented out this part of
> the code, and Firefox started responding correctly to the CSS file again (as
> shown in Picture 10).
>
>
>
> I don't know if it is Firefox not understanding the charset or whether it
> just doesn't like the charset at all, but either way it is a problem.  For
> the moment, I'll just be leaving this code commented out, but I would
> appreciate some advice on the best way to fix this.
>
>
>
> Please let me know if you need any more information.
>
>
>
> Bruce.
>
> --
> www.brucecooper.net - 0417 986 274
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2370606