Skip to content

Commit

Permalink
refactor(dynamite,dynamite_runtime)!: Always send cookies for all req…
Browse files Browse the repository at this point in the history
…uests

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Apr 3, 2024
1 parent a590fe2 commit e37b775
Show file tree
Hide file tree
Showing 32 changed files with 360 additions and 364 deletions.
8 changes: 4 additions & 4 deletions packages/dynamite/dynamite/example/lib/petstore.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class $Client extends _i1.DynamiteClient {
tags: tags,
limit: limit,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $findPets_Serializer();
final _rawResponse = await _i1.ResponseConverter<BuiltList<Pet>, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -185,7 +185,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $addPet_Request(
newPet: newPet,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $addPet_Serializer();
final _rawResponse = await _i1.ResponseConverter<Pet, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -248,7 +248,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $findPetById_Request(
id: id,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $findPetById_Serializer();
final _rawResponse = await _i1.ResponseConverter<Pet, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -310,7 +310,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $deletePet_Request(
id: id,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $deletePet_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, void>(_serializer).convert(_response);
Expand Down
2 changes: 1 addition & 1 deletion packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ ${allocate(returnType)}(
..body = Code.scope(
(allocate) => '''
final _request = \$${name}_Request($rawParameters);
final _response = await $client.sendWithCookies(_request);
final _response = await $client.send(_request);
final _serializer = \$${name}_Serializer();
final _rawResponse = await ${allocate(responseConverterType)}(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$noAuthentication_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<JsonObject, void>> noAuthentication() async {
final _request = $noAuthentication_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $noAuthentication_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -137,7 +137,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$basicAuthentication_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<JsonObject, void>> basicAuthentication() async {
final _request = $basicAuthentication_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $basicAuthentication_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -199,7 +199,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$bearerAuthentication_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<JsonObject, void>> bearerAuthentication() async {
final _request = $bearerAuthentication_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $bearerAuthentication_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -261,7 +261,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$multipleAuthentications_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<JsonObject, void>> multipleAuthentications() async {
final _request = $multipleAuthentications_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $multipleAuthentications_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class $Client extends _i1.DynamiteClient {
tags: tags,
limit: limit,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $findValues_Serializer();
final _rawResponse = await _i1.ResponseConverter<Object1, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -191,7 +191,7 @@ class $NonRootClientClient {
/// * [$setMode_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<Object1, void>> setMode() async {
final _request = $setMode_Request();
final _response = await _rootClient.sendWithCookies(_request);
final _response = await _rootClient.send(_request);

final _serializer = $setMode_Serializer();
final _rawResponse = await _i1.ResponseConverter<Object1, void>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$$get_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<void, GetHeaders>> $get() async {
final _request = $$get_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, GetHeaders>(_serializer).convert(_response);
Expand Down Expand Up @@ -121,7 +121,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$withContentOperationId_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<void, WithContentOperationIdHeaders>> withContentOperationId() async {
final _request = $withContentOperationId_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $withContentOperationId_Serializer();
final _rawResponse =
Expand Down Expand Up @@ -167,7 +167,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$getWithContent_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<Uint8List, GetWithContentHeaders>> getWithContent() async {
final _request = $getWithContent_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $getWithContent_Serializer();
final _rawResponse = await _i1.ResponseConverter<Uint8List, GetWithContentHeaders>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class $Client extends _i1.DynamiteClient {
anyOf: anyOf,
enumPattern: enumPattern,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -428,7 +428,7 @@ class $Client extends _i1.DynamiteClient {
anyOf: anyOf,
enumPattern: enumPattern,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $getHeaders_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -479,7 +479,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $getPathParameter_Request(
pathParameter: pathParameter,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $getPathParameter_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -566,7 +566,7 @@ class $Client extends _i1.DynamiteClient {
parameters: parameters,
headers: headers,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $getNamingCollisions_Serializer();
final _rawResponse = await _i1.ResponseConverter<JsonObject, void>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $$get_Request(
uint8List: uint8List,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -128,7 +128,7 @@ class $Client extends _i1.DynamiteClient {
final _request = $$post_Request(
string: string,
);
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$post_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, void>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$$get_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<String, void>> $get() async {
final _request = $$get_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<String, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -118,7 +118,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$$put_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<String, void>> $put() async {
final _request = $$put_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$put_Serializer();
final _rawResponse = await _i1.ResponseConverter<String, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -166,7 +166,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$$post_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<String, void>> $post() async {
final _request = $$post_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$post_Serializer();
final _rawResponse = await _i1.ResponseConverter<String, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -213,7 +213,7 @@ class $Client extends _i1.DynamiteClient {
/// * [$$patch_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<String, void>> $patch() async {
final _request = $$patch_Request();
final _response = await sendWithCookies(_request);
final _response = await send(_request);

final _serializer = $$patch_Serializer();
final _rawResponse = await _i1.ResponseConverter<String, void>(_serializer).convert(_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class $FirstClient {
/// * [$$get_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<void, void>> $get() async {
final _request = $$get_Request();
final _response = await _rootClient.sendWithCookies(_request);
final _response = await _rootClient.send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, void>(_serializer).convert(_response);
Expand Down Expand Up @@ -131,7 +131,7 @@ class $SecondClient {
/// * [$$get_Serializer] for a converter to parse the `Response` from an executed request.
Future<_i1.DynamiteResponse<void, void>> $get() async {
final _request = $$get_Request();
final _response = await _rootClient.sendWithCookies(_request);
final _response = await _rootClient.send(_request);

final _serializer = $$get_Serializer();
final _rawResponse = await _i1.ResponseConverter<void, void>(_serializer).convert(_response);
Expand Down
22 changes: 9 additions & 13 deletions packages/dynamite/dynamite_runtime/lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,27 @@ class DynamiteClient with http.BaseClient {
request.bodyBytes = body;
}

return sendWithCookies(request);
return send(request);
}

/// Sends an HTTP request and asynchronously returns the response.
///
/// Cookies are persisted in the [cookieJar] and loaded for requests.
Future<http.StreamedResponse> sendWithCookies(http.BaseRequest request) async {
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
if (cookieJar != null) {
final cookies = await cookieJar!.loadForRequest(request.url);
if (cookies.isNotEmpty) {
request.headers['cookie'] = cookies.join('; ');
}
}

final response = await send(request);
// Do not overwrite request headers to avoid invalid requests.
baseHeaders?.forEach((key, value) {
request.headers.putIfAbsent(key, () => value);
});

final response = await httpClient.send(request);

final cookieHeader = response.headersSplitValues['set-cookie'];
if (cookieHeader != null && cookieJar != null) {
Expand All @@ -117,14 +123,4 @@ class DynamiteClient with http.BaseClient {

return response;
}

@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
// Do not overwrite request headers to avoid invalid requests.
baseHeaders?.forEach((key, value) {
request.headers.putIfAbsent(key, () => value);
});

return httpClient.send(request);
}
}
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/utils/request_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class RequestManager {
cacheKey: cacheKey,
subject: subject,
request: () async {
final response = await account.client.sendWithCookies(request);
final response = await account.client.send(request);
return ResponseConverter<B, H>(serializer).convert(response);
},
unwrap: (rawResponse) => unwrap(rawResponse),
Expand Down

0 comments on commit e37b775

Please sign in to comment.