update client_config on go

Oct 31, 2014 at 8:39 AM
hi,
I am not sure that i use right patter, so please correct me. I am writing a library that communicates with server. In constructor i receive url and immediately create uniq_ptr<http_client> with specified URL as constructor parameter. I reuse this client for different requests by using uri_builder (is this Ok pattern?).

Later I can receive user/name and password and will want to update client_config with credentials. but _mainClient->client_config() returns const object that does not allow change.

Why? What is right way to handle this?

Thank you,
Dennis
Oct 31, 2014 at 5:42 PM
Hi Dennis,

Reusing http_client for different requests to different URIs - yes this is ok as long as they all share the same host name. For example you could construct the http_client with http://www.myserver.com and then make requests to different paths, hitting http://www.myserver.com/path1 and http://www.myserver.com/path2 for example.

The http_client configuration isn't mutable because the setting specified are used when connecting the client, they can't be updated after the connection is established. You have two options. One is don't create the http_client instance until you actually have the credentials. Another is use a second different http_client with your credentials.

Steve