@@ -4,38 +4,21 @@ import { API } from './api';
44
55/** A generic client request. */
66interface SentryRequest {
7- url : string ;
8- headers : { [ key : string ] : string } ;
97 body : string ;
8+ url : string ;
9+ // headers would contain auth & content-type headers for @sentry/node, but
10+ // since @sentry /browser avoids custom headers to prevent CORS preflight
11+ // requests, we can use the same approach for @sentry/browser and @sentry/node
12+ // for simplicity -- no headers involved.
13+ // headers: { [key: string]: string };
1014}
1115
1216/** Creates a SentryRequest from an event. */
13- export function eventToSentryRequest ( event : Event , api : API , extraHeaders ?: { [ key : string ] : string } ) : SentryRequest {
17+ export function eventToSentryRequest ( event : Event , api : API ) : SentryRequest {
1418 const useEnvelope = event . type === 'transaction' ;
1519
1620 const req : SentryRequest = {
1721 body : JSON . stringify ( event ) ,
18- headers : {
19- // To simplify maintenance, eventToSentryRequest is used by both
20- // @sentry /browser and @sentry /node.
21- //
22- // In @sentry /browser we want to avoid CORS preflight requests and thus we
23- // want to ensure outgoing requests are "simple requests" as explained in
24- // https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests.
25- //
26- // Therefore, we do not include any custom headers (auth goes in the query
27- // string instead) and we are limited in the values of Content-Type. If we
28- // were to not set the Content-Type header, browsers fill it in as
29- // `text/plain`, which is rejected by Relay for envelopes. If we set it to
30- // the empty string, current versions of mainstream browsers seem to
31- // respect it and despite empty string not being in the list of accepted
32- // values for "simple requests", empirically browsers do not send
33- // preflight requests in that case.
34- //
35- // 'Content-Type': useEnvelope ? 'application/x-sentry-envelope' : 'application/json',
36- 'Content-Type' : '' ,
37- ...extraHeaders ,
38- } ,
3922 url : useEnvelope ? api . getEnvelopeEndpointWithUrlEncodedAuth ( ) : api . getStoreEndpointWithUrlEncodedAuth ( ) ,
4023 } ;
4124
0 commit comments