<commit_before>//
//  NetRequestImpl.cpp
//  RhoAppBaseLib
//
//  Created by <NAME> on 17.02.15.
//
//

#import "IPhoneNetRequest.h"

#import "common/RhoFile.h"
#import "common/RhoFilePath.h"
#import "common/StringConverter.h"

class IURLRequestDelegate
{
public:
  virtual ~IURLRequestDelegate() {}
  
  virtual void start() = 0;
  virtual void onDone() = 0;
  virtual bool verifySSLPeers() = 0;
  virtual void onResponse(NSHTTPURLResponse* r) = 0;
  virtual void onData(NSData* d) = 0;
  virtual bool allowRedirects() = 0;
};

@interface ConnDelegate : NSObject<NSURLConnectionDataDelegate/*,NSURLConnectionDownloadDelegate*/>

{
@public
  IURLRequestDelegate* m_pCppDelegate;
  
  NSHTTPURLResponse* response;
  NSError* error;
  NSData* data;
}

- (id) init:(IURLRequestDelegate*)delegate;

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response;

/*
- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *) destinationURL;

- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes;
*/

@property (retain)NSHTTPURLResponse* response;
@property (retain)NSError* error;
@property (retain)NSData* data;

@end

@implementation ConnDelegate

  - (id) init:(IURLRequestDelegate*)delegate
  {
    self = [super init];
    m_pCppDelegate = delegate;
    return self;
  }

  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
  {
    self.error = err;
    m_pCppDelegate->onDone();
  }

  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)resp
  {
    self.response = (NSHTTPURLResponse*)resp;
    m_pCppDelegate->onResponse((NSHTTPURLResponse*)resp);
  }

  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d
  {
    self.data = d;
    m_pCppDelegate->onData(d);
  }

  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
    m_pCppDelegate->onDone();
  }

  - (void)startAsyncConnection
  {
    m_pCppDelegate->start();
  }

  - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
  {
    
    if ( (!m_pCppDelegate->verifySSLPeers()) && [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] )
    {
      [challenge.sender cancelAuthenticationChallenge:challenge];
    }
    else
    {
      [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
    }
  }

  - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
  {
    return m_pCppDelegate->allowRedirects()?request:nil;
  }

/*
  - (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *) destinationURL
  {
  }

  - (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes
  {
  }
*/

  @synthesize error;
  @synthesize response;
  @synthesize data;


@end<commit_msg>call onDone when not redirecting, otherwise NetRequest will hang<commit_after>//
//  NetRequestImpl.cpp
//  RhoAppBaseLib
//
//  Created by <NAME> on 17.02.15.
//
//

#import "IPhoneNetRequest.h"

#import "common/RhoFile.h"
#import "common/RhoFilePath.h"
#import "common/StringConverter.h"

class IURLRequestDelegate
{
public:
  virtual ~IURLRequestDelegate() {}
  
  virtual void start() = 0;
  virtual void onDone() = 0;
  virtual bool verifySSLPeers() = 0;
  virtual void onResponse(NSHTTPURLResponse* r) = 0;
  virtual void onData(NSData* d) = 0;
  virtual bool allowRedirects() = 0;
};

@interface ConnDelegate : NSObject<NSURLConnectionDataDelegate/*,NSURLConnectionDownloadDelegate*/>

{
@public
  IURLRequestDelegate* m_pCppDelegate;
  
  NSHTTPURLResponse* response;
  NSError* error;
  NSData* data;
}

- (id) init:(IURLRequestDelegate*)delegate;

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response;

/*
- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *) destinationURL;

- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes;
*/

@property (retain)NSHTTPURLResponse* response;
@property (retain)NSError* error;
@property (retain)NSData* data;

@end

@implementation ConnDelegate

  - (id) init:(IURLRequestDelegate*)delegate
  {
    self = [super init];
    m_pCppDelegate = delegate;
    return self;
  }

  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
  {
    self.error = err;
    m_pCppDelegate->onDone();
  }

  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)resp
  {
    self.response = (NSHTTPURLResponse*)resp;
    m_pCppDelegate->onResponse((NSHTTPURLResponse*)resp);
  }

  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d
  {
    self.data = d;
    m_pCppDelegate->onData(d);
  }

  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
    m_pCppDelegate->onDone();
  }

  - (void)startAsyncConnection
  {
    m_pCppDelegate->start();
  }

  - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
  {
    
    if ( (!m_pCppDelegate->verifySSLPeers()) && [challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] )
    {
      [challenge.sender cancelAuthenticationChallenge:challenge];
    }
    else
    {
      [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
    }
  }

  - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
  {
    if ( m_pCppDelegate->allowRedirects() )
    {
      return request;
    }
    
    m_pCppDelegate->onDone();
    return nil;
  }

/*
  - (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *) destinationURL
  {
  }

  - (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long) expectedTotalBytes
  {
  }
*/

  @synthesize error;
  @synthesize response;
  @synthesize data;


@end
{'fraction_non_alphanumeric': 0.11872573952616784, 'fraction_numerical': 0.0032124213626020613, 'mean_word_length': 5.671428571428572, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7584183', 'n_tokens_mistral': 2403, 'n_tokens_neox': 2219, 'n_words': 384}