Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Safe and Idempotent methods

 
Jose Luis Huertas
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm studying for the SCWCD and apparently I have found contradictions between the HTTP spec and the Servlet spec when they are talking about safe and idempotents methods.

Safe: 'The method is used only for retrieval, without any other side effect'
Idempotent: 'The effect produced by 1 request is the same produced by N (N > 0) requests'

According to HTTP spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html):
SAFE: GET, HEAD, OPTIONS, TRACE
NOT SAFE: POST, PUT, DELETE

IDEMPOTENT: GET, HEAD, OPTIONS, TRACE, PUT, DELETE
NOT IDEMPOTENT: POST

According to Servlet Spec (see the Javadoc of the do...() methods, http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html):

SAFE: GET, HEAD, OPTIONS, TRACE
NOT SAFE: POST, PUT, DELETE

IDEMPOTENT: GET, HEAD, OPTIONS, TRACE
NOT IDEMPOTENT: POST, PUT, DELETE

So I think there is a contradiction with the idempotence of the PUT and DELETE methods because the HTTP spec says "The methods GET, HEAD, PUT and DELETE share this property" and the Servlet spec says "This method does not need to be either safe or idempotent".

What do you think? Should PUT and DELETE be idempotent (I think so)? What should I answer if I found a question about this in the exam?

BTW, what about CONNECT? Could the "idempotence" or "safety" concepts be applied to this method?

Thanks in advance,

Jose Luis.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say you think so for DELETE and PUT but you do not say why.

If you did a PUT once, it would result in a file existing on the server. Do the same request again, and you still have just that one file on the server.

Same with DELETE. Do it once, file is gone. Do it twice, file is still gone.

There's no difference whether you perform the request once or a million times.
 
Jose Luis Huertas
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly Marc, I totally agree with you and the HTTP spec

That's why I don't understand what the servlet spec says in the doPut() and doDelete() methods: "This method does not need to be either safe or idempotent"

It seems clear that they are not safe (they have side effects) but as you exposed, they seem to be idempotent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic