@@ -106,13 +106,9 @@ public function sendShare(ICloudFederationShare $share) {
106106
107107 $ client = $ this ->httpClientService ->newClient ();
108108 try {
109- $ response = $ client ->post ($ ocmProvider ->getEndPoint () . '/shares ' , [
109+ $ response = $ client ->post ($ ocmProvider ->getEndPoint () . '/shares ' , array_merge ( $ this -> getDefaultRequestOptions (), [
110110 'body ' => json_encode ($ share ->getShare ()),
111- 'headers ' => ['content-type ' => 'application/json ' ],
112- 'verify ' => !$ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' , false ),
113- 'timeout ' => 10 ,
114- 'connect_timeout ' => 10 ,
115- ]);
111+ ]));
116112
117113 if ($ response ->getStatusCode () === Http::STATUS_CREATED ) {
118114 $ result = json_decode ($ response ->getBody (), true );
@@ -143,13 +139,9 @@ public function sendCloudShare(ICloudFederationShare $share): IResponse {
143139
144140 $ client = $ this ->httpClientService ->newClient ();
145141 try {
146- return $ client ->post ($ ocmProvider ->getEndPoint () . '/shares ' , [
142+ return $ client ->post ($ ocmProvider ->getEndPoint () . '/shares ' , array_merge ( $ this -> getDefaultRequestOptions (), [
147143 'body ' => json_encode ($ share ->getShare ()),
148- 'headers ' => ['content-type ' => 'application/json ' ],
149- 'verify ' => !$ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' , false ),
150- 'timeout ' => 10 ,
151- 'connect_timeout ' => 10 ,
152- ]);
144+ ]));
153145 } catch (\Throwable $ e ) {
154146 $ this ->logger ->error ('Error while sending share to federation server: ' . $ e ->getMessage (), ['exception ' => $ e ]);
155147 try {
@@ -175,13 +167,9 @@ public function sendNotification($url, ICloudFederationNotification $notificatio
175167
176168 $ client = $ this ->httpClientService ->newClient ();
177169 try {
178- $ response = $ client ->post ($ ocmProvider ->getEndPoint () . '/notifications ' , [
170+ $ response = $ client ->post ($ ocmProvider ->getEndPoint () . '/notifications ' , array_merge ( $ this -> getDefaultRequestOptions (), [
179171 'body ' => json_encode ($ notification ->getMessage ()),
180- 'headers ' => ['content-type ' => 'application/json ' ],
181- 'verify ' => !$ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' , false ),
182- 'timeout ' => 10 ,
183- 'connect_timeout ' => 10 ,
184- ]);
172+ ]));
185173 if ($ response ->getStatusCode () === Http::STATUS_CREATED ) {
186174 $ result = json_decode ($ response ->getBody (), true );
187175 return (is_array ($ result )) ? $ result : [];
@@ -205,13 +193,9 @@ public function sendCloudNotification(string $url, ICloudFederationNotification
205193
206194 $ client = $ this ->httpClientService ->newClient ();
207195 try {
208- return $ client ->post ($ ocmProvider ->getEndPoint () . '/notifications ' , [
196+ return $ client ->post ($ ocmProvider ->getEndPoint () . '/notifications ' , array_merge ( $ this -> getDefaultRequestOptions (), [
209197 'body ' => json_encode ($ notification ->getMessage ()),
210- 'headers ' => ['content-type ' => 'application/json ' ],
211- 'verify ' => !$ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' , false ),
212- 'timeout ' => 10 ,
213- 'connect_timeout ' => 10 ,
214- ]);
198+ ]));
215199 } catch (\Throwable $ e ) {
216200 $ this ->logger ->error ('Error while sending notification to federation server: ' . $ e ->getMessage (), ['exception ' => $ e ]);
217201 try {
@@ -230,4 +214,17 @@ public function sendCloudNotification(string $url, ICloudFederationNotification
230214 public function isReady () {
231215 return $ this ->appManager ->isEnabledForUser ('cloud_federation_api ' );
232216 }
217+
218+ private function getDefaultRequestOptions (): array {
219+ $ options = [
220+ 'headers ' => ['content-type ' => 'application/json ' ],
221+ 'timeout ' => 10 ,
222+ 'connect_timeout ' => 10 ,
223+ ];
224+
225+ if ($ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' )) {
226+ $ options ['verify ' ] = false ;
227+ }
228+ return $ options ;
229+ }
233230}
0 commit comments