Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create function to manually add cookies #76

Closed
xxorathaa opened this issue Jun 16, 2022 · 6 comments · Fixed by #77
Closed

create function to manually add cookies #76

xxorathaa opened this issue Jun 16, 2022 · 6 comments · Fixed by #77
Labels
enhancement New feature or request

Comments

@xxorathaa
Copy link

in the past we could add cookies via:

Future<void> addCookieToRequests(String name, String value) async {
  final Map<String, String> savedCookies = await Requests.getStoredCookies(Requests.getHostname(serviceUrl));
  savedCookies[name] = value;
  await Requests.setStoredCookies(Requests.getHostname(serviceUrl), savedCookies);
}

now the working solution is more complex:

// ignore: implementation_imports
import 'package:requests/src/cookie.dart';
...
Future<void> addCookieToRequests(String name, String value) async {
  final CookieJar cookieJar = await Requests.getStoredCookies(Requests.getHostname(serviceUrl));
  cookieJar.delegate[name] = Cookie(name, value);
  await Requests.setStoredCookies(Requests.getHostname(serviceUrl), cookieJar);
}

if instead Requests exposed a function to add cookies this could be simplified to something like:
Requests.addCookie(String url, String name, dynamic value);

in this way we would not have any need to expose the cookies.dart file as well as having a clean handling of cookies.

@sehnryr sehnryr added the enhancement New feature or request label Jun 16, 2022
@sehnryr
Copy link
Collaborator

sehnryr commented Jun 16, 2022

Hi, I think it would be better like that too. As I have integrated cookie handling with CookieJar, I didn't really thought about the drawbacks.

I'll add this feature right away!

@xxorathaa
Copy link
Author

@sehnryr appreciate the speed on this one. i tried it out and had some difficulties. after tinkering for a minute i found that i need to still call a different Requests function

      String serviceUrl = 'www.domain.com'
      await Requests.addCookie(Requests.getHostname(serviceUrl), name, value);

as opposed to:

      String serviceUrl = 'www.domain.com'
      await Requests.addCookie(serviceUrl, name, value);

obviously calling getHostname(serviceUrl) works, but was this intended? do you think there could be value in having both one that takes a url as a human readable string and allows Requests to call getHostname() internally in addition to what you have already added?

@sehnryr
Copy link
Collaborator

sehnryr commented Jun 17, 2022

@xxorathaa To be honest with you, I just thought of making it similar to the other methods. But now that you mention it, I think it would be better if the other methods could also take the url instead of the hostname.

@xxorathaa
Copy link
Author

cool, will keep my eyes on the changelog! i'm in no rush for it considering we have a way to make it work already, but i appreciate your getting back to me and the attention your giving to this issue.

@sehnryr sehnryr mentioned this issue Jun 18, 2022
9 tasks
@sehnryr
Copy link
Collaborator

sehnryr commented Jun 19, 2022

@xxorathaa I've opened #78, do you think there should be more to add?

@xxorathaa
Copy link
Author

xxorathaa commented Jun 19, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants