Noncopyable HTTPRequest class

Please post support and help requests here.
Posts: 4
Joined: 08 Jan 2012, 21:52

Noncopyable HTTPRequest class

Postby Paranaix » 12 Oct 2013, 16:01

This is actually not a real support request but rather a suggestion; I hope this board/subsection is still suited for this, otherwise please move this thread.

Im wondering why the Poco::Net::HTTPRequest, Poco::Net::HTTPResponse and Poco::Net::HTTPMessage classes are non copyable, this doesnt make any sense for me, sorry. These classes represent data models and the regular way to deal with models is RAII. Although, dealing with them as stack variables is kind of hard because the copy constructor is private and there is absolutely no reason for it. I didnt advance into the deep deep cores of these classes, but a quick look didnt revealed any resource that must be threaten specially due to some internal state. Unfortunately the documentation does not state anything about this matter.

Instead of giving arguments against the current behaviour, I can also give arguments for the proposed one (making them copyable). In my usecase I have to send multiple requests to various URIs but with some common headers and cookies. Thats why I wanted to implement a "BuildRequest" method returning a HTTPRequest. Now I have to do a workaround and write a "FillRequest" method taking a reference or pointer to a HTTPRequest object. The same applies to my planned "SendRequest" method which should besides sending the request also perform some cleanup in case something went wrong. The received HTTPResponse was supposed to be returned from that method. Now I probably have to return a pointer leaving the caller with the responsibility to clean up ressources; both are rather workarounds than good design.

I hope that I didnt sound to upset, but the little things are what tarnish an in other respects outstanding library.

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Noncopyable HTTPRequest class

Postby guenter » 14 Oct 2013, 23:17

There wasn't really a need yet to make these classes copyable, so I did not implement copy constructor and assignment operator. The base class Poco::Net::NameValueCollection supports copying, so it should not be much work to add this for HTTPMessage and subclasses. A pull request is welcome if you want to do it yourself.

And regarding returning a pointer: make it a Poco::SharedPtr, then at least you won't have to deal with manually deleting the object.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 5 guests