0

I have made up a simple http server using libevent. The way the resource (folders in my case) are accessed is

http://serverAddress:port/path/to/resouce/

the path to resource is extracted using the decoded url . It works fine on Linux as request would be something like this

http://severAddress:port/home/vickey/folder

but on window$ request is

http://serverAddress:port/c:/users/vickey/folder

which results in decoded url as /c:/users/vickey/folder. Its manually possible to remove the leading slash to correct the problem. However since I m using and learning boost libraries in my code I was wondering if there was some implementation of this sort ? I tried using native() and relative_path(). Thanks.

Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126

1 Answers1

0

Its definitely possible to do as you're asking, but I would suggest a different approach. How about creating a configuration property for the server which could be called RESOURCE_BASE_PATH. The resource path received in the URL would be appended to the RESOURCE_BASE_PATH to create the complete path.

This is pretty standard for FTP and HTTP servers and the like. On Windows, it could be set to "c:" and on Linux, left blank which would default to "/".

Also remember on Windows the slashes (\) are different than those on Unix (/).

Brady
  • 10,207
  • 2
  • 20
  • 59