こんにちわ。
いまさらですが、今年で入社して1年がたちました。
お祝いにルートビアをいただきました。
飲んだその日は、しばらくお腹が痛かったです。
話は変わって、Internet Explorer 8のちょっと困った挙動に悩まされました。
PUTリクエストを送信し、303 See Other レスポンスコードを受け取ると、
リダイレクト先にPUTリクエストを送信してしまうのです。
リダイレクト先を、リクエスト送信先と同じにしていた場合
PUT -> リダイレクト -> PUT -> リダイレクト...
と、PUTリクエストを延々と投げ続けてしまいます。
RFC2616(http://www.ietf.org/rfc/rfc2616.txt)には
"10.3.4 303 See Other The response to the request can be found under a different URI and
SHOULD be retrieved using a GET method on that resource."
とあるので、リダイレクト先にはGETリクエストを投げるべきではないかと思うのですが...。この挙動はPUTとDELETEで起こりました。GETとPOSTに関しては、リダイレクト先にGETリクエストを送信します。動作の確認に使ったコードは以下のものです。
python2.4 と web.py0.3、jQuery1.2.6で動作確認しました。
ディレクトリ構成は以下の通りです。
.
├ server.py
└ tmp/
├ Index.html
└ jQuery.js
server.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import web
import mako
urls = (
"/", "Index",
"/jquery", "Jquery"
)
app = web.application(urls, globals())
app.internalerror = web.debugerror
render = web.template.render('tmp/')
class Index:
def GET(self):
return render.Index(posted = "")
def POST(self):
#post_string = web.input().posted
return web.seeother(web.ctx.path)
def PUT(self):
return web.seeother(web.ctx.path)
def DELETE(self):
return web.seeother(web.ctx.path)
class Jquery:
def GET(self):
jquery = open("tmp/jquery.js", "r")
return jquery
if __name__ == '__main__':
app.run()
------------------------------------------------------------
HTML
-- Index.html --
$def with (posted)
<head>
<meta http-equiv="content-script-type" content="text/javascript" />
<script type="text/javascript" src="/jquery" charset="utf-8"></script>
<script type="text/javascript">
<!--
$$(document).ready(function(){
alert("hello");
$$("#test").click(function(){
$$.ajax({
url: "/",
type: "PUT",
dataType: "html",
data: null,
beforeSend: function(){
alert("before");
return true;
},
success: function(){
alert("success");
},
complete: function(){
alert("comp");
},
error: function(){
alert("error");
}
});
});
});
//-->
</script>
</head>
<html>
<body>
<form method="POST" id="test_form" action="/" >
<input type="button" id="test" name="test" value="put_test"/>
</form>
<p>${posted}</p>
</body>
</html>




Leave a comment