title: How can I implement chunked http requests on iPhone?
body: <p>Currently I'm trying to use a NSMutableURLRequest, setting the HTTPBody to a custom written NSInputStream of mine that provides this chunks.</p>
  
  <p>This would be fine if it were not for the fact that NSMutableURLRequest keeps asking me to implement more and more methods in my NSInputStream class. First it asked me to implement - streamStatus: and that was rather straightforward to implement however now it's asking for _scheduleInCFRunLoop:forMode:...</p>
  
  <p>Basically I'm generating data out of an algorithm and would like to send it to the server via chunked request.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>@interface GERHTTPChunkInputStream : NSInputStream
  {
    uint8_t counter_;
  }
  
  - (GERHTTPChunkInputStream *)init;
  - (void)dealloc;
  - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;
  - (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len;
  - (BOOL)hasBytesAvailable;
  - (NSStreamStatus)streamStatus;
  
  @end
  
  @implementation GERHTTPChunkInputStream
  
  - (GERHTTPChunkInputStream *)init {
    [super init];
    return self;
  }
  
  - (void)dealloc {
    assert(NO);
    [super dealloc];
  }
  
  - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len {
    NSLog(@"Getting more bytes!!!");
    for (int i = 0; i &lt; len; ++i) {
      buffer[i] = ++counter_;
    }
    return len;
  }
  
  - (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len {
    return NO;
  }
  
  - (BOOL)hasBytesAvailable {
    return YES;
  }
  
  - (NSStreamStatus)streamStatus {
    return NSStreamStatusNotOpen;
  }
  
  @end
  </code></pre>