Serving files with THttpServer

Is it possible to configure THttpServer like apache2 to serve files located in the directory dir, so that the client loads css and img files, for example

  <link rel="stylesheet" href="style.css">
<img src="image.jpg"> 

Cheers, Rok

Welcome to the ROOT Forum!
See the THttpServer Class Reference and especially THttpServer::AddLocation()

Thanks, it works as you suggested. I append the example:

root [0]
Processing test.cxx...
Info in <THttpEngine::Create>: Starting HTTP server on port 8080
void test(int port=8080){
  auto serv=new THttpServer(Form("http:%d",port));
  gSystem->Exec(Form("curl http://localhost:%d/www/%s.cxx",port,__func__));
  cout << endl;

Cheers, Rok

1 Like

Should files served in this way be openable using TFile::Open() ?
When I try, I get errors like this:

root [0] auto inFile = TFile::Open("http://localhost:8080/currentdir/out.root");
Error in <TWebFile::GetLine>: error receiving data from host localhost
Error in <TWebFile::GetLine>: error receiving data from host localhost
Error in <TWebFile::GetFromWeb10>: error receiving expected amount of data (got 0, expected 4) from host localhost

I can open the file at the same URL using a web browser and wget.

Hi @cosmic,

Yes, seems to be ROOT cannot read files via http protocol, which are served by THttpServer.
I will try to investigate why.


Problem fixed in master and 6.22 branch.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.