<commit_before>//
//  AuthChallengeViewController.swift
//  Example
//
//  Created by <NAME> on 25.10.17.
//  Copyright © 2017 MokuMokuCloud. All rights reserved.
//

import UIKit
import WebKit
import RxWebKit
import RxSwift
import RxCocoa

class AuthChallengeViewController: UIViewController {

    let bag = DisposeBag()
    let wkWebView = WKWebView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(wkWebView)
        wkWebView.load(URLRequest(url: URL(string: "https://jigsaw.w3.org/HTTP/Basic/")!))
        
        wkWebView.rx
            .didReceiveChallenge
            .debug("didReceiveChallenge")
            .subscribe(onNext: {(webView, challenge, handler) in
                let credential = URLCredential(user: "guest-bad-user", password: "<PASSWORD>", persistence: URLCredential.Persistence.forSession)
                challenge.sender?.use(credential, for: challenge)
                handler(URLSession.AuthChallengeDisposition.useCredential, credential)
            })
            .disposed(by: bag)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let originY = UIApplication.shared.statusBarFrame.maxY
        wkWebView.frame = CGRect(x: 0, y: originY, width: view.bounds.width, height: view.bounds.height)
    }

}
<commit_msg>Updated auth challenge example<commit_after>//
//  AuthChallengeViewController.swift
//  Example
//
//  Created by <NAME> on 25.10.17.
//  Copyright © 2017 MokuMokuCloud. All rights reserved.
//

import UIKit
import WebKit
import RxWebKit
import RxSwift
import RxCocoa

class AuthChallengeViewController: UIViewController {

    let bag = DisposeBag()
    let wkWebView = WKWebView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(wkWebView)
        wkWebView.load(URLRequest(url: URL(string: "https://jigsaw.w3.org/HTTP/Basic/")!))
        
        wkWebView.rx
            .didReceiveChallenge
            .debug("didReceiveChallenge")
            .subscribe(onNext: {(webView, challenge, handler) in
                guard challenge.previousFailureCount == 0 else {
                    handler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
                    return
                }
                /*
                 The correct credentials is as follows:
                 
                 user = guest
                 password = <PASSWORD>
                 
                 but I want you to start with the failed credentials so you see how it works.
                 However enjoys :)
                */
                let credential = URLCredential(user: "bad-user", password: "<PASSWORD>", persistence: URLCredential.Persistence.forSession)
                challenge.sender?.use(credential, for: challenge)
                handler(URLSession.AuthChallengeDisposition.useCredential, credential)
            })
            .disposed(by: bag)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let originY = UIApplication.shared.statusBarFrame.maxY
        wkWebView.frame = CGRect(x: 0, y: originY, width: view.bounds.width, height: view.bounds.height)
    }

}

{'fraction_non_alphanumeric': 0.09436881188118812, 'fraction_numerical': 0.007735148514851485, 'mean_word_length': 2.2041625371655105, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7378920', 'n_tokens_mistral': 966, 'n_tokens_neox': 887, 'n_words': 200}