Is it possible to send a 401 Unauthorized AND redirect (with a Location)?

By definition (see RFC 2616), the HTTP 302 response code is the redirect code. Without it, the location header may be ignored. However, you can send an HTTP 401 response and still display output. Instead of redirecting the user to an error page, you could simply write your content you want to send in the … Read more

Cannot handle 302 redirect in ajax and why? [duplicate]

You shouldn’t redirect the call when it’s an XHR but respond with a 401 Unauthorized and handle this in your callbacks. I don’t know ASP.NET but I did something similar with Spring Security. Heres the concept: Get the authenticated state Check the headers for X-Requested-With: XMLHttpRequest When found and not authenticated respond with 401 Unauthorized … Read more

Parsing HTTP User-Agent string

I finally decided to write my own, and I am happy with the outcome. Please feel free to use/modify/send me patches, etc. It’s here: http://pypi.python.org/pypi/httpagentparser Usage example: >>> import httpagentparser >>> s = “Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.9 (KHTML, like Gecko) \ Chrome/5.0.307.11 Safari/532.9” >>> print(httpagentparser.simple_detect(s)) (‘Linux’, ‘Chrome 5.0.307.11’) >>> print(httpagentparser.detect(s)) {‘os’: {‘name’: … Read more

How to properly use Bearer tokens?

1.Improving the security because if token is not sent in the header that sent in url, it will be logged by the network system, the server log …. 2.A good function to get Bearer tokens /** * Get header Authorization * */ function getAuthorizationHeader(){ $headers = null; if (isset($_SERVER[‘Authorization’])) { $headers = trim($_SERVER[“Authorization”]); } else … Read more

Operating System from User-Agent HTTP Header [closed]

Here’s a quick list… let me know if I missed one you are interested in. http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html: // Match user agent string with operating systems Windows 3.11 => Win16, Windows 95 => (Windows 95)|(Win95)|(Windows_95), Windows 98 => (Windows 98)|(Win98), Windows 2000 => (Windows NT 5.0)|(Windows 2000), Windows XP => (Windows NT 5.1)|(Windows XP), Windows Server 2003 … Read more