1
1
// Copyright 2020 Contributors to the Parsec project.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- use std :: sync :: atomic :: AtomicBool ;
3
+ use crate :: utils :: service_builder :: DEFAULT_BUFFER_SIZE_LIMIT ;
4
4
use std:: sync:: atomic:: Ordering ;
5
+ use std:: sync:: atomic:: { AtomicBool , AtomicUsize } ;
5
6
6
7
/// Configuration values that affect most or all the
7
8
/// components of the service.
8
9
#[ derive( Default , Debug ) ]
9
10
pub struct GlobalConfig {
10
11
log_error_details : AtomicBool ,
12
+ buffer_size_limit : AtomicUsize ,
11
13
}
12
14
13
15
impl GlobalConfig {
14
16
const fn new ( ) -> Self {
15
17
GlobalConfig {
16
18
log_error_details : AtomicBool :: new ( false ) ,
19
+ buffer_size_limit : AtomicUsize :: new ( DEFAULT_BUFFER_SIZE_LIMIT ) , // 1 MB
17
20
}
18
21
}
19
22
@@ -22,18 +25,26 @@ impl GlobalConfig {
22
25
pub fn log_error_details ( ) -> bool {
23
26
GLOBAL_CONFIG . log_error_details . load ( Ordering :: Relaxed )
24
27
}
28
+
29
+ /// Fetch the size limit for buffers within responses (in bytes).
30
+ /// information about the error
31
+ pub fn buffer_size_limit ( ) -> usize {
32
+ GLOBAL_CONFIG . buffer_size_limit . load ( Ordering :: Relaxed )
33
+ }
25
34
}
26
35
27
36
static GLOBAL_CONFIG : GlobalConfig = GlobalConfig :: new ( ) ;
28
37
29
38
pub ( super ) struct GlobalConfigBuilder {
30
39
log_error_details : bool ,
40
+ buffer_size_limit : Option < usize > ,
31
41
}
32
42
33
43
impl GlobalConfigBuilder {
34
44
pub fn new ( ) -> Self {
35
45
GlobalConfigBuilder {
36
46
log_error_details : false ,
47
+ buffer_size_limit : None ,
37
48
}
38
49
}
39
50
@@ -43,9 +54,19 @@ impl GlobalConfigBuilder {
43
54
self
44
55
}
45
56
57
+ pub fn with_buffer_size_limit ( mut self , buffer_size_limit : usize ) -> Self {
58
+ self . buffer_size_limit = Some ( buffer_size_limit) ;
59
+
60
+ self
61
+ }
62
+
46
63
pub fn build ( self ) {
47
64
GLOBAL_CONFIG
48
65
. log_error_details
49
66
. store ( self . log_error_details , Ordering :: Relaxed ) ;
67
+ GLOBAL_CONFIG . buffer_size_limit . store (
68
+ self . buffer_size_limit . unwrap_or ( DEFAULT_BUFFER_SIZE_LIMIT ) ,
69
+ Ordering :: Relaxed ,
70
+ ) ;
50
71
}
51
72
}
0 commit comments