Proper HTTP headers for login success / fail responses?

The header that the server sends is either the 200 OK or 401 denied status codes on success or failure. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Section 10.4.2 401 Unauthorized for this. When sending the 401, the server must send a WWW-Authenticate = “WWW-Authenticate” “:” 1#challenge to indicate what scheme should be used to authenticate. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html Section 14.47 … Read more

Web API: Content in HttpResponseMessage

HttpResponseMessage<T> was removed after Beta. Right now, instead of a typed HttpResponseMessage we have a typed ObjectContent If you manually create HttpResponseMessage using its default parameterless constructor, there is no request context available to perform content negotiation – that’s why you need to specify the formatter, or perform content negotiation by hand. I understand you … Read more

Express 4.14 – How to send 200 status with a custom message?

You can use: res.status(200).send(‘some text’); if you want to pass number to the send method, convert it to string first to avoid deprecation error message. the deprecation is for sending status directly inside send. res.send(200) // <- is deprecated BTW – the default status is 200, so you can simply use res.send(‘Success 1’). Use .status() … Read more

Web API Best Approach for returning HttpResponseMessage

Although this is not directly answering the question, I wanted to provide some information I found usefull. http://weblogs.asp.net/dwahlin/archive/2013/11/11/new-features-in-asp-net-web-api-2-part-i.aspx The HttpResponseMessage has been more or less replaced with IHttpActionResult. It is much cleaner an easier to use. public IHttpActionResult Get() { Object obj = new Object(); if (obj == null) return NotFound(); return Ok(obj); } Then … Read more

Which HTTP errors should never trigger an automatic retry?

There are some errors that should not be retried because they seem permanent: 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 409 Conflict – it depends 410 Gone 411 Length Required 412 Precondition Failed 413 Payload Too Large  414 URI Too Long … Read more

AttributeError: can’t set attribute

This answer doesn’t address the specifics of this question, but explains the underlying issue. This specific exception “AttributeError: can’t set attribute” is raised (see source) when the attribute you’re attempting to change is actually a property that doesn’t have a setter. If you have access to the library’s code, adding a setter would solve the … Read more

What’s the proper way to set the Location header for an HTTP 201 response in a Java Servlet application

Just send the absolute path. The restriction to an absolute URI is a known defect in RFC 2616 and will be fixed in HTTPbis (see http://trac.tools.ietf.org/wg/httpbis/trac/ticket/185). Please note that RFC 7231 now includes relative URIs in the spec. See other answers for how to handle relative URIs.

Django: Add response header when using render or render_to_response

Assign the result of render to a variable, set the header, then return the response. response = render(request, “template.html”, {}) response[‘Cache-Control’] = ‘no-cache’ return response Most of the time, it is simpler to user render than render_to_response. However, if you are using render_to_response, the same approach will work: response = render_to_response(“template.html”, {}) response[‘Cache-Control’] = ‘no-cache’ … Read more

tech