1

I have a web service provided by jetty. How can i filter URL with illegal characters?

I can not control some return information when the request URL has illegal characters.

actually, i want to return some specific info when the URL is invalid. for example: i added a filter in my application to validate the URL, if illegal then i will return defined info.

but, I can not filter some URL like "%adsasd", it seem be handled by jetty.

curl -v -X PUT -u user:password 'http://myip.com:8080/%adsasd'

*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'user'
> PUT /%adsasd HTTP/1.1
> Authorization: Basic YWRtaW46MTIzNDU2
> User-Agent: curl/7.35.0
> Accept: */*
> Host:127.0.0.1:8080
>  < HTTP/1.1 400 Bad Request 
   < Content-Length: 0
* Server Jetty(9.0.6.v20130930) is not blacklisted 
   < Server: Jetty(9.0.6.v20130930) < 
* Connection #0 to host 127.0.0.1 left intact
4

1 回答 1

0

来自 Jetty 的错误响应

HTTP/1.1 400 Bad Request

表示 Jetty 确实将其检测为错误的 URL 并拒绝了它。

至于如何定制这个,那真的很棘手,主要是因为它在处理这个特定请求时发生的时间有多早。

这种错误 ( 400 Bad Request) 发生在解析原始传入 http 请求的过程中,甚至在服务器容器甚至试图弄清楚要与什么上下文对话之前。

无法在特定的 webapp 上下文中使用自定义错误处理程序来处理这种基本的 http 错误。由于服务器还没有弄清楚要与之交谈的上下文。

服务器端(即使在全局级别)也无法自定义此错误消息。

如果您想要这样的功能,请提交功能请求

于 2014-09-28T14:51:17.953 回答