Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTPServer response and css file

Please post support and help requests here.

HTTPServer response and css file

Postby helthans » 22 May 2014, 14:55

Hi,

I have an implementation using Poco::Net::HTTPServer. My question is regarding the http server response:
In one case I want to deliver a html. I understand how to create a simple html response, for which I have the following:
Code: Select all
void RequestHandler::invalidRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp, std::string uriQuery)
{
    resp.setContentType("text/html");
    resp.setVersion("HTTP/1.1");
    std::ostream& ostr = resp.send();
    ostr << "<h1>Invalid Request</h1>";
    ostr << "You have sent an <b>INVALID</b> request <br />";
    ostr << "Bye-Bye";
}


Now, how do I create a html response which contains images and have dependencies to css-files?
helthans
 
Posts: 14
Joined: 05 Nov 2013, 15:07

Re: HTTPServer response and css file

Postby alex » 22 May 2014, 15:53

Those will typically be files, right? If so, examine the request URI, find the requested file in your local filesystem and send it back verbatim.
alex
 
Posts: 1158
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: HTTPServer response and css file

Postby fbraem » 22 May 2014, 21:28

Take a look on my project MQWeb : https://github.com/fbraem/mqweb
I use the first part of a URI path to decide which requesthandler to create. When it is "static", I use the StaticRequestHandler which returns files: https://github.com/fbraem/mqweb/blob/ma ... andler.cpp
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 112
Joined: 11 Aug 2008, 22:47
Location: Belgium

Re: HTTPServer response and css file

Postby gregee123 » 23 May 2014, 15:25

I hope this is still within the general topic of this thread...

fbraem wrote:https://github.com/fbraem/mqweb/blob/master/MQWeb/src/StaticRequestHandler.cpp


@fbraem

Does calling setStatus() AFTER sendFile() make sense? Just seemed odd to me.

Code: Select all
      response.sendFile(staticPath.toString(), mimeType);
      response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
      return;
currently using: 1.5.4
gregee123
 
Posts: 64
Joined: 29 Mar 2013, 12:11

Re: HTTPServer response and css file

Postby guenter » 23 May 2014, 15:32

No, changing anything in the response after calling any of the send() methods does not make sense.
Btw, it also does not make sense to call setVersion on the response. This will be set automatically based on the version of the request.
guenter
 
Posts: 1166
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTPServer response and css file

Postby fbraem » 29 May 2014, 15:33

gregee123 wrote:Does calling setStatus() AFTER sendFile() make sense? Just seemed odd to me.

You are right. :oops:

Franky
Zumuta!, that's the way to do IT!
fbraem
 
Posts: 112
Joined: 11 Aug 2008, 22:47
Location: Belgium


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests