{"id":2453,"date":"2022-08-30T15:24:59","date_gmt":"2022-08-30T15:24:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/12\/play-framework-websocket-get-browser-info-from-request-header-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:59","modified_gmt":"2022-08-30T15:24:59","slug":"play-framework-websocket-get-browser-info-from-request-header-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/play-framework-websocket-get-browser-info-from-request-header-collection-of-common-programming-errors\/","title":{"rendered":"Play framework (Websocket): get browser info from request header-Collection of common programming errors"},"content":{"rendered":"<p>Actually play framework gives us everything (even a lot of know headers name). This is the code within a controller class&#8217; static function<\/p>\n<pre><code>public class Application extends Controller {\n    public static Result index() {\n        String userAgent = request().headers().get(Http.HeadersNames.USER_AGENT);\n        return ok(userAgent);\n    }\n}\n<\/code><\/pre>\n<p>Naturally I assume you are pointing to routes.Application.index() somewhere in your routes file.<\/p>\n<p>If you are also wondering how to parse the user agent,I also advise you to check out :<br \/>\nhttps:\/\/code.google.com\/p\/user-agent-utils\/<\/p>\n<p>I used it in a project 6 months ago, I do not know how updated it is but it has worked great for me when I needed it for more usefull and readable informations.<\/p>\n<h2>Some browser do not fully implement what WebSockets protocol should have<\/h2>\n<p>After all it is a protocol still under definition\/development.<\/p>\n<p>For chrome it is a bug with a ticket https:\/\/code.google.com\/p\/chromium\/issues\/detail?id=128170<\/p>\n<p>Apparently it has been fixed recently and should be rolled out soon? I assume it is the same with Safari.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-12 20:51:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Actually play framework gives us everything (even a lot of know headers name). This is the code within a controller class&#8217; static function public class Application extends Controller { public static Result index() { String userAgent = request().headers().get(Http.HeadersNames.USER_AGENT); return ok(userAgent); } } Naturally I assume you are pointing to routes.Application.index() somewhere in your routes file. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2453","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2453"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2453\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}