Я вклав наступне у web.xml моєї програми, щоб спробувати заборонити PUT, DELETE тощо:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>SEARCH</http-method>
<http-method>COPY</http-method>
<http-method>MOVE</http-method>
<http-method>PROPFIND</http-method>
<http-method>PROPPATCH</http-method>
<http-method>MKCOL</http-method>
<http-method>LOCK</http-method>
<http-method>UNLOCK</http-method>
<http-method>delete</http-method>
<http-method>put</http-method>
<http-method>search</http-method>
<http-method>copy</http-method>
<http-method>move</http-method>
<http-method>propfind</http-method>
<http-method>proppatch</http-method>
<http-method>mkcol</http-method>
<http-method>lock</http-method>
<http-method>unlock</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Гаразд, тепер:
Якщо я роблю запит методом, DELETEя отримую 403 назад.
Якщо я роблю запит методом, deleteя отримую 403 назад.
АЛЕ
Якщо я роблю запит методом, DeLeTeя отримую нормально!
Як я можу зробити так, щоб заборонити ці чутливі до регістру справи?
Редагувати: я тестую його за допомогою програми C #:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "making request";
System.Threading.Thread.Sleep(400);
WebRequest req = WebRequest.Create("http://serverurl/Application/cache_test.jsp");
req.Method = txtMethod.Text;
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
textBox1.Text = "Status: " + resp.StatusCode;
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
WebHeaderCollection header = resp.Headers;
using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream(), ASCIIEncoding.ASCII))
{
//string responseText = reader.ReadToEnd();
textBox1.Text += "\r\n" + reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
}
txtMethod.Textце текстове поле, де я набираю ім'я методу. Коли є 403, викидається виняток, який потрапляє у блок лову.
Cache_test.jsp містить:
<%
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");
out.print("Method used was: "+request.getMethod());
%>
HttpWebRequestбуде регістронезавісімого розпізнавати і перетворювати стандартні методи HTTP в верхній регістр. Крім того, це документально підтверджено лише як стандартні методи HTTP. Найкращий варіант - використовувати необроблений потік TCP (наприклад, в netcat, PuTTY raw, або telnet тощо).