@@ -224,6 +224,10 @@ prepare_tus_request_common(
224224 h -> key = "x-sentry-auth" ;
225225 h -> value = sentry__dsn_get_auth_header (dsn , user_agent );
226226
227+ h = & req -> headers [req -> headers_len ++ ];
228+ h -> key = "content-type" ;
229+ h -> value = sentry__string_clone (TUS_MIME );
230+
227231 h = & req -> headers [req -> headers_len ++ ];
228232 h -> key = "tus-resumable" ;
229233 h -> value = sentry__string_clone ("1.0.0" );
@@ -236,46 +240,18 @@ prepare_tus_request_common(
236240}
237241
238242static sentry_prepared_http_request_t *
239- prepare_tus_upload_request (
240- const char * location , const sentry_path_t * path , size_t file_size )
243+ prepare_tus_request ( const sentry_path_t * path , size_t file_size ,
244+ const sentry_dsn_t * dsn , const char * user_agent )
241245{
242- if (!location || ! path ) {
246+ if (!path ) {
243247 return NULL ;
244248 }
245-
246249 sentry_prepared_http_request_t * req
247- = SENTRY_MAKE (sentry_prepared_http_request_t );
248- if (!req ) {
249- return NULL ;
250- }
251- memset (req , 0 , sizeof (* req ));
252-
253- req -> headers = sentry_malloc (
254- sizeof (sentry_prepared_http_header_t ) * TUS_MAX_HTTP_HEADERS );
255- if (!req -> headers ) {
256- sentry_free (req );
257- return NULL ;
250+ = prepare_tus_request_common (file_size , dsn , user_agent );
251+ if (req ) {
252+ req -> body_path = sentry__path_clone (path );
253+ req -> body_len = file_size ;
258254 }
259- req -> headers_len = 0 ;
260-
261- req -> method = "PATCH" ;
262- req -> url = sentry__string_clone (location );
263- req -> body_path = sentry__path_clone (path );
264- req -> body_len = file_size ;
265-
266- sentry_prepared_http_header_t * h ;
267- h = & req -> headers [req -> headers_len ++ ];
268- h -> key = "tus-resumable" ;
269- h -> value = sentry__string_clone ("1.0.0" );
270-
271- h = & req -> headers [req -> headers_len ++ ];
272- h -> key = "content-type" ;
273- h -> value = sentry__string_clone (TUS_MIME );
274-
275- h = & req -> headers [req -> headers_len ++ ];
276- h -> key = "upload-offset" ;
277- h -> value = sentry__string_clone ("0" );
278-
279255 return req ;
280256}
281257
@@ -330,9 +306,8 @@ tus_upload_ref(http_transport_state_t *state, const sentry_path_t *att_dir,
330306 return false;
331307 }
332308
333- // Step 1: TUS creation request (POST, no body)
334- sentry_prepared_http_request_t * req
335- = prepare_tus_request_common (file_size , state -> dsn , state -> user_agent );
309+ sentry_prepared_http_request_t * req = prepare_tus_request (
310+ att_file , file_size , state -> dsn , state -> user_agent );
336311 if (!req ) {
337312 sentry__path_free (att_file );
338313 return false;
@@ -363,42 +338,19 @@ tus_upload_ref(http_transport_state_t *state, const sentry_path_t *att_dir,
363338 return false;
364339 }
365340
366- // Step 2: TUS upload request (PATCH with file body)
367- req = prepare_tus_upload_request (resp .location , att_file , file_size );
368- char * location = resp .location ;
369- resp .location = NULL ;
370- http_response_cleanup (& resp );
371-
372- if (!req ) {
373- sentry__path_free (att_file );
374- sentry_free (location );
375- return false;
376- }
377-
378- memset (& resp , 0 , sizeof (resp ));
379- ok = state -> send_func (state -> client , req , & resp );
380- sentry__prepared_http_request_free (req );
381- http_response_cleanup (& resp );
382-
383- if (!ok || resp .status_code != 204 ) {
384- sentry__path_free (att_file );
385- sentry_free (location );
386- return false;
387- }
388-
389341 const char * ref_ct = sentry_value_as_string (
390342 sentry_value_get_by_key (entry , "content_type" ));
391343 const char * att_type = sentry_value_as_string (
392344 sentry_value_get_by_key (entry , "attachment_type" ));
393345 sentry_value_t att_length
394346 = sentry_value_get_by_key (entry , "attachment_length" );
395347 sentry_value_incref (att_length );
396- sentry__envelope_add_attachment_ref (send_envelope , location , filename ,
348+ sentry__envelope_add_attachment_ref (send_envelope , resp . location , filename ,
397349 * ref_ct ? ref_ct : NULL , * att_type ? att_type : NULL , att_length );
398350
399351 sentry__path_remove (att_file );
400352 sentry__path_free (att_file );
401- sentry_free ( location );
353+ http_response_cleanup ( & resp );
402354 return true;
403355}
404356
@@ -745,16 +697,9 @@ sentry__http_transport_get_bgworker(sentry_transport_t *transport)
745697}
746698
747699sentry_prepared_http_request_t *
748- sentry__prepare_tus_create_request (
749- size_t file_size , const sentry_dsn_t * dsn , const char * user_agent )
750- {
751- return prepare_tus_request_common (file_size , dsn , user_agent );
752- }
753-
754- sentry_prepared_http_request_t *
755- sentry__prepare_tus_upload_request (
756- const char * location , const sentry_path_t * path , size_t file_size )
700+ sentry__prepare_tus_request (const sentry_path_t * path , size_t file_size ,
701+ const sentry_dsn_t * dsn , const char * user_agent )
757702{
758- return prepare_tus_upload_request ( location , path , file_size );
703+ return prepare_tus_request ( path , file_size , dsn , user_agent );
759704}
760705#endif
0 commit comments