8000 [selenium-crawler] Fix sitemap transformer to work with basic auth by vkepin · Pull Request #4658 · vividus-framework/vividus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[selenium-crawler] Fix sitemap transformer to work with basic auth #4658

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

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

vkepin
Copy link
Contributor
@vkepin vkepin commented Dec 11, 2023

No description provided.

@vkepin vkepin requested a review from a team as a code owner December 11, 2023 16:44
@vkepin vkepin force-pushed the httpclient_basicauth branch 3 times, most recently from e359af7 to fa3cbe0 Compare December 13, 2023 09:11
@vkepin vkepin changed the title [http-client] Add support of requests with basic authentication [selenium-crawler] WIP Fix sitemap transformer to work with basic auth Dec 13, 2023
@vkepin vkepin force-pushed the httpclient_basicauth branch from fa3cbe0 to 9581295 Compare December 13, 2023 09:19
Comment on lines 72 to 101
HttpClientContext context = new HttpClientContext();
HttpResponse response = httpClient.doHttpGet(siteMapUrl, context);
HttpGet request = new HttpGet(siteMapUrl);
URIAuthority currentAuthority = request.getAuthority();
String authorityUserInfo = currentAuthority.getUserInfo();
if (authorityUserInfo != null)
{
URIAuthority newAuthority = new URIAuthority(null, currentAuthority.getHostName(),
currentAuthority.getPort());
request.setAuthority(newAuthority);

UriUtils.UserInfo userInfo = UriUtils.parseUserInfo(URLDecoder.decode(authorityUserInfo,
StandardCharsets.UTF_8));
Credentials credentials = new UsernamePasswordCredentials(userInfo.user(),
userInfo.password().toCharArray());
BasicScheme scheme = new BasicScheme();
scheme.initPreemptive(credentials);
AuthCache authCache = new BasicAuthCache();
try
{
HttpHost host = HttpHost.create(request.getUri());
authCache.put(host, scheme);
}
catch (URISyntaxException e)
{
throw new IllegalArgumentException(e);
}
context.setAuthCache(authCache);
}
HttpResponse response = httpClient.execute(request, context);
URI cleanSiteMapUrl = UriUtils.removeUserInfo(getBaseUri(context, siteMapUrl));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            ContextBuilder contextBuilder = ContextBuilder.create();
            UserInfo userInfo = UriUtils.getUserInfo(siteMapUrl);
            URI targetSiteMapUrl;
            if (userInfo != null)
            {
                targetSiteMapUrl = UriUtils.removeUserInfo(siteMapUrl);

                contextBuilder.preemptiveBasicAuth(
                        HttpHost.create(targetSiteMapUrl),
                        new UsernamePasswordCredentials(userInfo.user(), userInfo.password().toCharArray())
                );
            }
            else
            {
                targetSiteMapUrl = siteMapUrl;
            }
            HttpClientContext context = contextBuilder.build();
            HttpResponse response = httpClient.doHttpGet(targetSiteMapUrl, context);
            URI cleanSiteMapUrl = getBaseUri(context, targetSiteMapUrl);

Credentials credentials = new UsernamePasswordCredentials(userInfo.user(),
userInfo.password().toCharArray());
BasicScheme scheme = new BasicScheme();
scheme.initPreemptive(credentials);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need preemptive basic auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to CredentialsProvider

@vkepin vkepin force-pushed the httpclient_basicauth branch from 9581295 to 7c0171d Compare December 13, 2023 16:13
Copy link
codecov bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4b1b72a) 97.39% compared to head (c52bac7) 97.39%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #4658   +/-   ##
=========================================
  Coverage     97.39%   97.39%           
- Complexity     6775     6783    +8     
=========================================
  Files           914      915    +1     
  Lines         18818    18843   +25     
  Branches       1252     1254    +2     
=========================================
+ Hits          18327    18352   +25     
  Misses          384      384           
  Partials        107      107           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vkepin vkepin force-pushed the httpclient_basicauth branch from 7c0171d to c52bac7 Compare December 13, 2023 16:43
@vkepin vkepin changed the title [selenium-crawler] WIP Fix sitemap transformer to work with basic auth [selenium-crawler] Fix sitemap transformer to work with basic auth Dec 13, 2023
@valfirst valfirst merged commit 2668dd0 into vividus-framework:master Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0