~roguescholar/jdownloader/browser

« back to all changes in this revision

Viewing changes to src/jd/http/Browser.java

  • Committer: psp
  • Date: 2024-09-18 13:44:17 UTC
  • Revision ID: svn-v4:ebf7c1c2-ba36-0410-9fe8-c592906822b4:browser:49821
Minor changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
464
464
        final String domain = Browser.getHost(host, includeSubdomain);
465
465
        if (domain == null) {
466
466
            throw new WTFException("Browser.getHost(host) returned null:" + host);
467
 
        } else {
468
 
            synchronized (Browser.REQUEST_INTERVAL_MAP) {
469
 
                Browser.setRequestIntervalLimitGlobal(domain, includeSubdomain, requestInterval);
470
 
                boolean notifyFlag = false;
471
 
                if (requestInterval <= 0 || burstRequests <= 0 || burstInterval <= 0) {
472
 
                    notifyFlag = Browser.REQUESTS_BURST_INTERVAL_MAP.remove(domain) != null;
473
 
                    // TODO merge/cleanup REQUESTS_BURST_REQUESTS_MAP
474
 
                } else {
475
 
                    final Integer existingBurstInterval = Browser.REQUESTS_BURST_INTERVAL_MAP.put(domain, burstInterval);
476
 
                    notifyFlag = existingBurstInterval == null || existingBurstInterval.intValue() != burstInterval;
477
 
                    Vector<Long> vector = Browser.REQUESTS_BURST_REQUESTS_MAP.get(domain);
478
 
                    if (vector == null) {
479
 
                        vector = new Vector<Long>(burstRequests);
480
 
                        Browser.REQUESTS_BURST_REQUESTS_MAP.put(domain, vector);
481
 
                    } else if (vector.capacity() != burstRequests) {
482
 
                        vector.ensureCapacity(burstRequests);
483
 
                        notifyFlag = true;
484
 
                    }
485
 
                }
486
 
                if (notifyFlag) {
487
 
                    Browser.REQUEST_INTERVAL_MAP.notifyAll();
488
 
                }
 
467
        }
 
468
        synchronized (Browser.REQUEST_INTERVAL_MAP) {
 
469
            Browser.setRequestIntervalLimitGlobal(domain, includeSubdomain, requestInterval);
 
470
            boolean notifyFlag = false;
 
471
            if (requestInterval <= 0 || burstRequests <= 0 || burstInterval <= 0) {
 
472
                notifyFlag = Browser.REQUESTS_BURST_INTERVAL_MAP.remove(domain) != null;
 
473
                // TODO merge/cleanup REQUESTS_BURST_REQUESTS_MAP
 
474
            } else {
 
475
                final Integer existingBurstInterval = Browser.REQUESTS_BURST_INTERVAL_MAP.put(domain, burstInterval);
 
476
                notifyFlag = existingBurstInterval == null || existingBurstInterval.intValue() != burstInterval;
 
477
                Vector<Long> vector = Browser.REQUESTS_BURST_REQUESTS_MAP.get(domain);
 
478
                if (vector == null) {
 
479
                    vector = new Vector<Long>(burstRequests);
 
480
                    Browser.REQUESTS_BURST_REQUESTS_MAP.put(domain, vector);
 
481
                } else if (vector.capacity() != burstRequests) {
 
482
                    vector.ensureCapacity(burstRequests);
 
483
                    notifyFlag = true;
 
484
                }
 
485
            }
 
486
            if (notifyFlag) {
 
487
                Browser.REQUEST_INTERVAL_MAP.notifyAll();
489
488
            }
490
489
        }
491
490
    }
964
963
    /**
965
964
     * Creates a new postrequest based an an requestVariable ArrayList
966
965
     *
967
 
     * @deprecated use {@link #createPostRequest(String, UrlQuery, String)
 
966
     * @deprecated use {@link #createPostRequest(String, UrlQuery, String)
968
967
     *
 
968
     * 
969
969
     */
970
970
    @Deprecated
971
971
    public PostRequest createPostRequest(String url, final List<KeyValueStringEntry> post, final String encoding) throws IOException {
1778
1778
    }
1779
1779
 
1780
1780
    /**
1781
 
     * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Site </br> auto completes Sec-Fetch-Site, some websites(eg
1782
 
     * facebook) check it
 
1781
     * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Site </br>
 
1782
     * auto completes Sec-Fetch-Site, some websites(eg facebook) check it
1783
1783
     */
1784
1784
    protected void autoCompleteHeaders(final Request request) {
1785
1785
        if (request != null) {
2436
2436
    }
2437
2437
 
2438
2438
    /**
2439
 
     * Sets Browser upper page load limit Byte value. </br> Use Integer.MAX_VALUE for "unlimited" (do not use "-1"!).
 
2439
     * Sets Browser upper page load limit Byte value. </br>
 
2440
     * Use Integer.MAX_VALUE for "unlimited" (do not use "-1"!).
2440
2441
     *
2441
2442
     * @since JD2
2442
2443
     * @param i
2581
2582
    }
2582
2583
 
2583
2584
    /**
2584
 
     * Checks for block by firewalls and similar. </br> To be called after a sent request.
 
2585
     * Checks for block by firewalls and similar. </br>
 
2586
     * To be called after a sent request.
2585
2587
     */
2586
2588
    public void checkForBlockedByAfterLoadConnection(Request request) throws IOException {
2587
2589
        if (this.getThrowExceptionOnBlockedBy(request)) {
2613
2615
            // TODO: Add separate BlockedType for Cloudflare-Captcha, see: https://svn.jdownloader.org/issues/90281
2614
2616
            /**
2615
2617
             * TODO: 2023-12-21: Maybe remove reliance on http status-code as it looks like literally any status code can be returned when a
2616
 
             * Cloudflare block happens. </br> I've just added code 502 to the list of "Cloudflare response-codes".
 
2618
             * Cloudflare block happens. </br>
 
2619
             * I've just added code 502 to the list of "Cloudflare response-codes".
2617
2620
             */
2618
2621
            /*
2619
2622
             * It is really important to also check for Cloudflare html else stuff will fail/break e.g. icerbox.com wrong login ->
3107
3110
                    return null;
3108
3111
                }
3109
3112
                if (true) { /*
3110
 
                 * TODO: Add header based detection too -> At least check "server" header so we do not only rely on html code.
3111
 
                 */
 
3113
                             * TODO: Add header based detection too -> At least check "server" header so we do not only rely on html code.
 
3114
                             */
3112
3115
                    /* See new ESET NOD32 html code 2023: https://board.jdownloader.org/showthread.php?t=91433 */
3113
3116
                    return null;
3114
3117
                } else if (request.containsHTML("<div class\\s*=\\s*\"prodhead\">\\s*<div class\\s*=\\s*\"logoimg\">\\s*<span class\\s*=\\s*\"logotxt\">\\s*ESET NOD32 Antivirus\\s*</span>\\s*</div>\\s*</div>") && request.containsHTML("- ESET NOD32 Antivirus\\s*</title>")) {
3215
3218
    }
3216
3219
 
3217
3220
    /**
3218
 
     * Returns true if any antiddos provider/other sort of blocking is blocking at this moment. </br> See also:
3219
 
     * https://svn.jdownloader.org/issues/89834
 
3221
     * Returns true if any antiddos provider/other sort of blocking is blocking at this moment. </br>
 
3222
     * See also: https://svn.jdownloader.org/issues/89834
3220
3223
     */
3221
3224
    public boolean isBlocked() {
3222
3225
        final Request request = this.getRequest();