Skip to content

Commit 217ad98

Browse files
authored
Merge pull request #10 from ionut-arm/conf
Make inner attributes configurable
2 parents d86a733 + 12037ca commit 217ad98

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

src/core/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ impl CoreClient {
5454
}
5555
}
5656

57+
/// Update the authentication data of the client
58+
pub fn set_auth_data(&mut self, auth_data: AuthenticationData) {
59+
self.auth_data = auth_data;
60+
}
61+
5762
/// list opcodes
5863
pub fn list_provider_operations(&self, provider: ProviderID) -> Result<HashSet<Opcode>> {
5964
let res = self.op_handler.process_operation(

src/core/operation_handler.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ use parsec_interface::requests::{
2929
#[derivative(Debug)]
3030
pub struct OperationHandler {
3131
#[derivative(Debug = "ignore")]
32-
converter: Box<dyn Convert>,
33-
version_maj: u8,
34-
version_min: u8,
35-
content_type: BodyType,
36-
accept_type: BodyType,
37-
request_client: RequestHandler,
32+
pub converter: Box<dyn Convert>,
33+
pub wire_protocol_version_maj: u8,
34+
pub wire_protocol_version_min: u8,
35+
pub content_type: BodyType,
36+
pub accept_type: BodyType,
37+
pub request_handler: RequestHandler,
3838
}
3939

4040
#[allow(clippy::new_without_default)]
@@ -58,8 +58,8 @@ impl OperationHandler {
5858
.operation_to_body(operation)
5959
.map_err(ClientErrorKind::Interface)?;
6060
let header = RequestHeader {
61-
version_maj: self.version_maj,
62-
version_min: self.version_min,
61+
version_maj: self.wire_protocol_version_maj,
62+
version_min: self.wire_protocol_version_min,
6363
provider,
6464
session: 0, // no provisioning of sessions yet
6565
content_type: self.content_type,
@@ -110,7 +110,7 @@ impl OperationHandler {
110110
let req_opcode = operation.opcode();
111111
let request = self.operation_to_request(operation, provider, auth)?;
112112

113-
let response = self.request_client.process_request(request)?;
113+
let response = self.request_handler.process_request(request)?;
114114
self.response_to_result(response, req_opcode)
115115
}
116116
}
@@ -119,11 +119,28 @@ impl Default for OperationHandler {
119119
fn default() -> Self {
120120
OperationHandler {
121121
converter: Box::from(ProtobufConverter {}),
122-
version_maj: 1,
123-
version_min: 0,
122+
wire_protocol_version_maj: 1,
123+
wire_protocol_version_min: 0,
124124
content_type: BodyType::Protobuf,
125125
accept_type: BodyType::Protobuf,
126-
request_client: Default::default(),
126+
request_handler: Default::default(),
127127
}
128128
}
129129
}
130+
131+
impl crate::CoreClient {
132+
/// Set the content type for requests and responses handled by this client
133+
pub fn set_request_content_type(&mut self, content_type: BodyType) {
134+
self.op_handler.content_type = content_type;
135+
self.op_handler.accept_type = content_type;
136+
match content_type {
137+
BodyType::Protobuf => self.op_handler.converter = Box::from(ProtobufConverter {}),
138+
}
139+
}
140+
141+
/// Set the wire protocol version numbers to be used by the client
142+
pub fn set_wire_protocol_version(&mut self, version_maj: u8, version_min: u8) {
143+
self.op_handler.wire_protocol_version_maj = version_maj;
144+
self.op_handler.wire_protocol_version_min = version_min;
145+
}
146+
}

src/core/request_handler.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,22 @@ impl Default for RequestHandler {
6060
}
6161
}
6262
}
63+
64+
impl crate::CoreClient {
65+
/// Set the maximum body size allowed for requests
66+
pub fn set_max_body_size(&mut self, max_body_size: usize) {
67+
self.op_handler.request_handler.max_body_size = max_body_size;
68+
}
69+
70+
/// Set the timeout allowed for operations on the IPC used for communicating with the service.
71+
///
72+
/// A value of `None` represents "no timeout"
73+
pub fn set_ipc_timeout(&mut self, timeout: Option<Duration>) {
74+
self.op_handler.request_handler.timeout = timeout;
75+
}
76+
77+
/// Set the location of the Unix Socket path where the service socket can be found
78+
pub fn set_socket_path(&mut self, socket_path: PathBuf) {
79+
self.op_handler.request_handler.socket_path = socket_path;
80+
}
81+
}

0 commit comments

Comments
 (0)