来自相对路径的绝对URL

我有一个基本URL和该文档中的一些相对URI我希望有绝对路径。

例如base = https://example.com/some/path.html?query=string和该文档中的相对URI:

  • index.html→ https://example.com/some/index.html
  • ..→ https://example.com/
  • ../../../../abc→https://example.com/abc
  • abc / ..→ https://example.com/some/
  • //example.org/→https://example.org/
  • ftp://example.net/→ftp://example.net/

在Java中,您有类URL实现:

URL abs = new URL(new URL(basePath), relPath); 

但奇怪的是,我找不到一个简单的C库或function实现这一点。

有没有图书馆certificate这个function? 或者更好的是一些可以使用的小型自包含文件?

你可以打赌这已经在C中写过一千次了。 例如,对于apache。

以下是一些指示:

libSoup,GNOME使用的http库: http : //developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base

为Boost库提出建议: http : //cpp-netlib.github.com/

谷歌自己(Chrome的一部分?): http : //code.google.com/p/google-url/

还有一个: http : //uriparser.sourceforge.net/

W3C: http : //www.w3.org/Library/src/HTParse

libcamel中的URL解析: http : //www.google.com/codesearch#KhbZeNk3OGk/camel/camel-url.c

一些URI解析API,似乎都没有相关的URI:

GLib,我最喜欢的C库: http : //developer.gnome.org/glib/unstable/glib-URI-Functions.html

libedataserver(来自Evolution) http://developer.gnome.org/libedataserver/stable/libedataserver-e-url.html

GNet,一个glib插件: http : //developer.gnome.org/gnet/stable/gnet-uri.html

对于Windows,您可以使用Urlmon.dll中的CoInternetCombineUrl或Shlwapi.lib中的UrlCombine 。 他们做同样的AFAIK。

Interesting Posts