From: Divye K. <div...@gm...> - 2008-08-27 17:01:23
|
On Wed, Aug 27, 2008 at 6:14 PM, Glyn Matthews <gly...@gm...>wrote: > Hello, > > > I have some questions about the way HTTP requests are made using the > current interface, specifically this (taken from the http_1_0_test.cpp): > > using namespace boost::network; > http::request request("http://www.boost.org/"); > http::client client_; > http::response response_; > response_ = client_.get(request); > > > What exactly is the role of the client here? I'm a little confused by the > syntax because it reads as though you're trying to make a get request to an > HTTP client. Would it perhaps be better to rename http::client to > http::connection? > Currently, I read the above code as: 1. frame a request for resource http://www.boost.org/ 2. Create a client that handles http requests/responses 3. Get the resource specified by the request and provide a response. However, I do admit that client.head(request) and client.put(request) don't seem to be too intuitive in that respect. > Secondly, why is the domain passed as an argument to the http::request > constructor? To me, this doesn't feel like the right unit of encapsulation. > > Does the following example code make more sense? > > using namespace boost::network; > http::connection c("http://www.boost.org"); > http::request request1("/users/news/version_1_36_0"); > http::response response1 = c.get(request); > http::request request2("/cgi-bin/path"); > request2 << body("post_body"); > http::response response2 = c.post(request2); > > Two observations about this: > The current implementation creates a new socket for each request that is > made, whereas the above suggestion allows a socket to remain open for > multiple requests. Additionally, the URI processing is currently done > inside the request constructor. I think it would be better to re-factor > this into a separate package. > > Any thoughts? > Glyn I agree with the plus point of having a socket remain open for multiple requests but the syntax suggested seems to separate the domain name and the relative path of the resource. I wouldn't like to keep track of which domain is associated with which domain. Also, this breaks encapsulation because a function that takes only a http::request cannot determine where the resource is located and which protocol is to be used. A part of that useful information lies in the connection object. In my head, a resource is completely specified only when its complete url/uri is available and in that respect, the request object is underspecified. Just my thoughts, Divye -- An idealist is one who, on noticing that a rose smells better than a cabbage, concludes that it will also make better soup. H. L. Mencken (1880 - 1956) My official web site: http://people.iitr.ernet.in/shp/061305/ Webmaster: http://www.drkapoorsclinic.com Blog: http://divyekapoor.blogspot.com |