ObjFW  Diff

Differences From Artifact [209c55758d]:

To Artifact [c6a81ba86b]:


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65







-







#define REDIRECTS_DEFAULT 10

@interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate>
{
@public
	OFHTTPClient *_client;
	OFHTTPRequest *_request;
	OFString *_requestString;
	unsigned int _redirects;
	id _context;
	bool _firstLine;
	OFString *_version;
	int _status;
	OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_serverHeaders;
}
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
274
275
276
277
278
279
280

281
282
283
284
285
286
287







-







	return self;
}

- (void)dealloc
{
	[_client release];
	[_request release];
	[_requestString release];
	[_context release];
	[_version release];
	[_serverHeaders release];

	[super dealloc];
}

553
554
555
556
557
558
559
560
561
562
563




564
565
566
567
568
569
570
571

572
573
574
575

576
577
578
579
580
581
582
583
584

585
586
587
588

589
590
591
592
593
594
595
596
597
598

599
600

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619






620
621
622
623
624
625
626
551
552
553
554
555
556
557




558
559
560
561
562
563
564
565
566
567
568

569
570
571
572

573
574
575
576
577



578

579
580
581
582

583
584
585
586
587
588
589
590
591
592

593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609





610
611
612
613
614
615
616
617
618
619
620
621
622







-
-
-
-
+
+
+
+







-
+



-
+




-
-
-

-
+



-
+









-
+

-
+














-
-
-
-
-
+
+
+
+
+
+







		[self raiseException: e];
		ret = false;
	}

	return ret;
}

- (size_t)stream: (OF_KINDOF(OFStream *))sock
  didWriteBuffer: (const void **)request
	  length: (size_t)length
       exception: (id)exception
- (OFData *)stream: (OF_KINDOF(OFStream *))stream
      didWriteData: (OFData *)data
      bytesWritten: (size_t)bytesWritten
	 exception: (id)exception
{
	if (exception != nil) {
		if ([exception isKindOfClass: [OFWriteFailedException class]] &&
		    ([exception errNo] == ECONNRESET ||
		    [exception errNo] == EPIPE)) {
			/* In case a keep-alive connection timed out */
			[self closeAndReconnect];
			return 0;
			return nil;
		}

		[self raiseException: exception];
		return 0;
		return nil;
	}

	_firstLine = true;

	[_requestString release];
	_requestString = nil;

	if ([[_request headers] objectForKey: @"Content-Length"] != nil) {
		[sock setDelegate: nil];
		[stream setDelegate: nil];

		OFStream *requestBody = [[[OFHTTPClientRequestBodyStream alloc]
		    initWithHandler: self
			     socket: sock] autorelease];
			     socket: stream] autorelease];

		if ([_client->_delegate respondsToSelector:
		    @selector(client:wantsRequestBody:request:context:)])
			[_client->_delegate client: _client
				  wantsRequestBody: requestBody
					   request: _request
					   context: _context];

	} else
		[sock asyncReadLine];
		[stream asyncReadLine];

	return 0;
	return nil;
}

- (void)handleSocket: (OFTCPSocket *)sock
{
	/*
	 * As a work around for a bug with split packets in lighttpd when using
	 * HTTPS, we construct the complete request in a buffer string and then
	 * send it all at once.
	 *
	 * We do not use the socket's write buffer in case we need to resend
	 * the entire request (e.g. in case a keep-alive connection timed out).
	 */

	@try {
		[_requestString release];
		_requestString = [constructRequestString(_request) retain];

		[sock asyncWriteBuffer: [_requestString UTF8String]
				length: [_requestString UTF8StringLength]];
		OFString *requestString = constructRequestString(_request);
		OFData *requestData = [OFData
		    dataWithItems: [requestString UTF8String]
			    count: [requestString UTF8StringLength]];

		[sock asyncWriteData: requestData];
	} @catch (id e) {
		[self raiseException: e];
		return;
	}
}

-     (void)socket: (OF_KINDOF(OFTCPSocket *))sock