标准的URL规范化 - Java

9
I would like to ask if there's any Java package or library that has the standard URL normalization. 5 Components of URL Representation: http://www[dot]example[dot]com:8040/folder/exist?name=sky#head 1. scheme: http 2. authority: www.example.com:8040 3. path: /folder/exist 4. query: ?name=sky 5. fragment: #head The 3 types of standard URL normalization: Syntax-Based Normalization - Case normalization – convert all letters at the scheme and authority components to lower case. - Percent-encoded normalization – decode any percent-encoded octet that corresponds to an unreserved character, such as %2D for hyphen and %5 for underscore. - Path segment normalization – remove dot-segments from the path component, such as ‘.’ and ‘..’.

基于Scheme的规范化

  • 在URL的授权组件后添加尾随斜杠“/”
  • 删除默认端口号,例如http方案的80
  • 截断URL的片段

基于协议的规范化

  • 仅在访问资源的结果等效时才适用
  • 例如,origin服务器将example.com/data重定向到example.com/data/
3个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
5

正如其他人提到的那样,java.net.URL和/或java.net.URI是一些明显的起点。

这里还有其他选项:

  1. Galimatias(西班牙语意为“胡言乱语”)似乎是一个偏执而相对受欢迎的Java URL规范化库。源代码可以在github.com/smola/galimatias找到。

    galimatias起初是因为对java.net.URL和java.net.URI感到失望而开始的。它们两个都适用于基本用例,但对于其他用例来说严重破坏

  2. github.com/sentric/url-normalization库提供了另一种(我认为不寻常的)方法,其中它颠倒了域名部分;例如,“com.stackoverflow”而不是“stackoverflow.com”。

您可以在Github上找到其他变体,有时会用Python、Ruby和PHP等语言实现。


3

0

关于java.net.URLset()怎么样?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,