@@ -225,10 +225,6 @@ prepare_tus_request_common(
225225 h -> key = "x-sentry-auth" ;
226226 h -> value = sentry__dsn_get_auth_header (dsn , user_agent );
227227
228- h = & req -> headers [req -> headers_len ++ ];
229- h -> key = "content-type" ;
230- h -> value = sentry__string_clone (TUS_MIME );
231-
232228 h = & req -> headers [req -> headers_len ++ ];
233229 h -> key = "tus-resumable" ;
234230 h -> value = sentry__string_clone ("1.0.0" );
@@ -241,18 +237,46 @@ prepare_tus_request_common(
241237}
242238
243239static sentry_prepared_http_request_t *
244- prepare_tus_request ( const sentry_path_t * path , size_t file_size ,
245- const sentry_dsn_t * dsn , const char * user_agent )
240+ prepare_tus_upload_request (
241+ const char * location , const sentry_path_t * path , size_t file_size )
246242{
247- if (!path ) {
243+ if (!location || ! path ) {
248244 return NULL ;
249245 }
246+
250247 sentry_prepared_http_request_t * req
251- = prepare_tus_request_common (file_size , dsn , user_agent );
252- if (req ) {
253- req -> body_path = sentry__path_clone (path );
254- req -> body_len = file_size ;
248+ = SENTRY_MAKE (sentry_prepared_http_request_t );
249+ if (!req ) {
250+ return NULL ;
251+ }
252+ memset (req , 0 , sizeof (* req ));
253+
254+ req -> headers = sentry_malloc (
255+ sizeof (sentry_prepared_http_header_t ) * TUS_MAX_HTTP_HEADERS );
256+ if (!req -> headers ) {
257+ sentry_free (req );
258+ return NULL ;
255259 }
260+ req -> headers_len = 0 ;
261+
262+ req -> method = "PATCH" ;
263+ req -> url = sentry__string_clone (location );
264+ req -> body_path = sentry__path_clone (path );
265+ req -> body_len = file_size ;
266+
267+ sentry_prepared_http_header_t * h ;
268+ h = & req -> headers [req -> headers_len ++ ];
269+ h -> key = "tus-resumable" ;
270+ h -> value = sentry__string_clone ("1.0.0" );
271+
272+ h = & req -> headers [req -> headers_len ++ ];
273+ h -> key = "content-type" ;
274+ h -> value = sentry__string_clone (TUS_MIME );
275+
276+ h = & req -> headers [req -> headers_len ++ ];
277+ h -> key = "upload-offset" ;
278+ h -> value = sentry__string_clone ("0" );
279+
256280 return req ;
257281}
258282
@@ -307,8 +331,9 @@ tus_upload_ref(http_transport_state_t *state, const sentry_path_t *att_dir,
307331 return false;
308332 }
309333
310- sentry_prepared_http_request_t * req = prepare_tus_request (
311- att_file , file_size , state -> dsn , state -> user_agent );
334+ // Step 1: TUS creation request (POST, no body)
335+ sentry_prepared_http_request_t * req
336+ = prepare_tus_request_common (file_size , state -> dsn , state -> user_agent );
312337 if (!req ) {
313338 sentry__path_free (att_file );
314339 return false;
@@ -339,19 +364,42 @@ tus_upload_ref(http_transport_state_t *state, const sentry_path_t *att_dir,
339364 return false;
340365 }
341366
367+ // Step 2: TUS upload request (PATCH with file body)
368+ req = prepare_tus_upload_request (resp .location , att_file , file_size );
369+ char * location = resp .location ;
370+ resp .location = NULL ;
371+ http_response_cleanup (& resp );
372+
373+ if (!req ) {
374+ sentry__path_free (att_file );
375+ sentry_free (location );
376+ return false;
377+ }
378+
379+ memset (& resp , 0 , sizeof (resp ));
380+ ok = state -> send_func (state -> client , req , & resp );
381+ sentry__prepared_http_request_free (req );
382+ http_response_cleanup (& resp );
383+
384+ if (!ok || resp .status_code != 204 ) {
385+ sentry__path_free (att_file );
386+ sentry_free (location );
387+ return false;
388+ }
389+
342390 const char * ref_ct = sentry_value_as_string (
343391 sentry_value_get_by_key (entry , "content_type" ));
344392 const char * att_type = sentry_value_as_string (
345393 sentry_value_get_by_key (entry , "attachment_type" ));
346394 sentry_value_t att_length
347395 = sentry_value_get_by_key (entry , "attachment_length" );
348396 sentry_value_incref (att_length );
349- sentry__envelope_add_attachment_ref (tus_envelope , resp . location , filename ,
397+ sentry__envelope_add_attachment_ref (tus_envelope , location , filename ,
350398 * ref_ct ? ref_ct : NULL , * att_type ? att_type : NULL , att_length );
351399
352400 sentry__path_remove (att_file );
353401 sentry__path_free (att_file );
354- http_response_cleanup ( & resp );
402+ sentry_free ( location );
355403 return true;
356404}
357405
@@ -772,9 +820,16 @@ sentry__http_transport_get_bgworker(sentry_transport_t *transport)
772820}
773821
774822sentry_prepared_http_request_t *
775- sentry__prepare_tus_request (const sentry_path_t * path , size_t file_size ,
776- const sentry_dsn_t * dsn , const char * user_agent )
823+ sentry__prepare_tus_create_request (
824+ size_t file_size , const sentry_dsn_t * dsn , const char * user_agent )
825+ {
826+ return prepare_tus_request_common (file_size , dsn , user_agent );
827+ }
828+
829+ sentry_prepared_http_request_t *
830+ sentry__prepare_tus_upload_request (
831+ const char * location , const sentry_path_t * path , size_t file_size )
777832{
778- return prepare_tus_request ( path , file_size , dsn , user_agent );
833+ return prepare_tus_upload_request ( location , path , file_size );
779834}
780835#endif
0 commit comments