MCPcopy Create free account
hub / github.com/RipMeApp/ripme / cookiesForURL

Method cookiesForURL

src/main/java/com/rarchives/ripme/utils/Http.java:76–114  ·  view source on GitHub ↗
(String u)

Source from the content-addressed store, hash-verified

74 }
75
76 private Map<String, String> cookiesForURL(String u) {
77 Map<String, String> cookiesParsed = new HashMap<>();
78
79 String cookieDomain = "";
80 try {
81 URL parsed = new URI(u).toURL();
82 String cookieStr = "";
83
84 String[] parts = parsed.getHost().split("\\.");
85
86 // if url is www.reddit.com, we should also use cookies from reddit.com;
87 // this rule is applied for all subdomains (for all rippers); e.g. also
88 // old.reddit.com, new.reddit.com
89 while (parts.length > 1) {
90 String domain = String.join(".", parts);
91 // Try to get cookies for this host from config
92 logger.info("Trying to load cookies from config for " + domain);
93 cookieStr = Utils.getConfigString("cookies." + domain, "");
94 if (!cookieStr.equals("")) {
95 cookieDomain = domain;
96 // we found something, start parsing
97 break;
98 }
99 parts = (String[]) ArrayUtils.remove(parts, 0);
100 }
101
102 if (!cookieStr.equals("")) {
103 cookiesParsed = RipUtils.getCookiesFromString(cookieStr.trim());
104 }
105 } catch (MalformedURLException | URISyntaxException e) {
106 logger.warn("Parsing url " + u + " while getting cookies", e);
107 }
108
109 if (cookiesParsed.size() > 0) {
110 logger.info("Cookies for " + cookieDomain + " have been added to this request");
111 }
112
113 return cookiesParsed;
114 }
115
116 // Setters
117 public Http timeout(int timeout) {

Callers 1

defaultSettingsMethod · 0.95

Calls 4

getConfigStringMethod · 0.95
getCookiesFromStringMethod · 0.95
removeMethod · 0.80
getHostMethod · 0.65

Tested by

no test coverage detected