-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add http response to event (#934)
- Loading branch information
Showing
11 changed files
with
469 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// See https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/configuration/options/#max-request-body-size | ||
import 'package:meta/meta.dart'; | ||
|
||
const _mediumSize = 10000; | ||
const _smallSize = 4000; | ||
|
||
/// Describes the size of http request bodies which should be added to an event | ||
enum MaxRequestBodySize { | ||
/// Request bodies are never sent | ||
never, | ||
|
||
/// Only small request bodies will be captured where the cutoff for small | ||
/// depends on the SDK (typically 4KB) | ||
small, | ||
|
||
/// Medium and small requests will be captured (typically 10KB) | ||
medium, | ||
|
||
/// The SDK will always capture the request body for as long as Sentry can | ||
/// make sense of it | ||
always, | ||
} | ||
|
||
extension MaxRequestBodySizeX on MaxRequestBodySize { | ||
bool shouldAddBody(int contentLength) { | ||
if (this == MaxRequestBodySize.never) { | ||
return false; | ||
} | ||
if (this == MaxRequestBodySize.always) { | ||
return true; | ||
} | ||
if (this == MaxRequestBodySize.medium && contentLength <= _mediumSize) { | ||
return true; | ||
} | ||
|
||
if (this == MaxRequestBodySize.small && contentLength <= _smallSize) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
/// Describes the size of http response bodies which should be added to an event | ||
/// This enum might be removed at any time. | ||
@experimental | ||
enum MaxResponseBodySize { | ||
/// Response bodies are never sent | ||
never, | ||
|
||
/// Only small response bodies will be captured where the cutoff for small | ||
/// depends on the SDK (typically 4KB) | ||
small, | ||
|
||
/// Medium and small response will be captured (typically 10KB) | ||
medium, | ||
|
||
/// The SDK will always capture the request body for as long as Sentry can | ||
/// make sense of it | ||
always, | ||
} | ||
|
||
extension MaxResponseBodySizeX on MaxResponseBodySize { | ||
bool shouldAddBody(int contentLength) { | ||
if (this == MaxResponseBodySize.never) { | ||
return false; | ||
} | ||
if (this == MaxResponseBodySize.always) { | ||
return true; | ||
} | ||
if (this == MaxResponseBodySize.medium && contentLength <= _mediumSize) { | ||
return true; | ||
} | ||
|
||
if (this == MaxResponseBodySize.small && contentLength <= _smallSize) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'contexts.dart'; | ||
|
||
/// The response interface contains information on a HTTP request related to the event. | ||
/// This is an experimental feature. It might be removed at any time. | ||
@experimental | ||
@immutable | ||
class SentryResponse { | ||
/// The tpye of this class in the [Contexts] field | ||
static const String type = 'response'; | ||
|
||
/// The URL of the response if available. | ||
/// This might be the redirected URL | ||
final String? url; | ||
|
||
/// Indicates whether or not the response is the result of a redirect | ||
/// (that is, its URL list has more than one entry). | ||
final bool? redirected; | ||
|
||
/// The body of the response | ||
final Object? body; | ||
|
||
/// The HTTP status code of the response. | ||
/// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status | ||
final int? statusCode; | ||
|
||
/// The status message for the corresponding [statusCode] | ||
final String? status; | ||
|
||
/// An immutable dictionary of submitted headers. | ||
/// If a header appears multiple times it, | ||
/// needs to be merged according to the HTTP standard for header merging. | ||
/// Header names are treated case-insensitively by Sentry. | ||
Map<String, String> get headers => Map.unmodifiable(_headers ?? const {}); | ||
|
||
final Map<String, String>? _headers; | ||
|
||
Map<String, String> get other => Map.unmodifiable(_other ?? const {}); | ||
|
||
final Map<String, String>? _other; | ||
|
||
SentryResponse({ | ||
this.url, | ||
this.body, | ||
this.redirected, | ||
this.statusCode, | ||
this.status, | ||
Map<String, String>? headers, | ||
Map<String, String>? other, | ||
}) : _headers = headers != null ? Map.from(headers) : null, | ||
_other = other != null ? Map.from(other) : null; | ||
|
||
/// Deserializes a [SentryResponse] from JSON [Map]. | ||
factory SentryResponse.fromJson(Map<String, dynamic> json) { | ||
return SentryResponse( | ||
url: json['url'], | ||
headers: json['headers'], | ||
other: json['other'], | ||
body: json['body'], | ||
statusCode: json['status_code'], | ||
status: json['status'], | ||
redirected: json['redirected'], | ||
); | ||
} | ||
|
||
/// Produces a [Map] that can be serialized to JSON. | ||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
if (url != null) 'url': url, | ||
if (headers.isNotEmpty) 'headers': headers, | ||
if (other.isNotEmpty) 'other': other, | ||
if (redirected != null) 'redirected': redirected, | ||
if (body != null) 'body': body, | ||
if (status != null) 'status': status, | ||
if (statusCode != null) 'status_code': statusCode, | ||
}; | ||
} | ||
|
||
SentryResponse copyWith({ | ||
String? url, | ||
bool? redirected, | ||
int? statusCode, | ||
String? status, | ||
Object? body, | ||
Map<String, String>? headers, | ||
Map<String, String>? other, | ||
}) => | ||
SentryResponse( | ||
url: url ?? this.url, | ||
headers: headers ?? _headers, | ||
redirected: redirected ?? this.redirected, | ||
other: other ?? _other, | ||
body: body ?? this.body, | ||
status: status ?? this.status, | ||
statusCode: statusCode ?? this.statusCode, | ||
); | ||
|
||
SentryResponse clone() => SentryResponse( | ||
body: body, | ||
headers: headers, | ||
other: other, | ||
redirected: redirected, | ||
status: status, | ||
statusCode: statusCode, | ||
url: url, | ||
); | ||
} |
Oops, something went wrong.