Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TIdCustomHTTP.ConnectToHost(ARequest: TIdHTTPRequest; AResponse: TIdHTTPResponse);
- var
- LLocalHTTP: TIdHTTPProtocol;
- begin
- ARequest.FUseProxy := SetHostAndPort;
- if ARequest.UseProxy = ctProxy then
- begin
- ARequest.URL := FURI.URI;
- end;
- case ARequest.UseProxy of
- ctNormal:
- if (ProtocolVersion = pv1_0) and (Length(ARequest.Connection) = 0) then
- ARequest.Connection := 'keep-alive';
- ctSSL, ctSSLProxy: ARequest.Connection := '';
- ctProxy:
- if (ProtocolVersion = pv1_0) and (Length(ARequest.Connection) = 0) then
- ARequest.ProxyConnection := 'keep-alive';
- end;
- if ARequest.UseProxy = ctSSLProxy then begin
- LLocalHTTP := TIdHTTPProtocol.Create(Self);
- with LLocalHTTP do begin
- Request.UserAgent := ARequest.UserAgent;
- Request.Host := ARequest.Host;
- Request.ContentLength := ARequest.ContentLength;
- Request.Pragma := 'no-cache';
- Request.URL := URL.Host + ':' + URL.Port;
- Request.Method := hmConnect;
- Request.ProxyConnection := 'keep-alive';
- Response.ContentStream := TMemoryStream.Create;
- try
- try
- repeat
- CheckAndConnect(Response);
- BuildAndSendRequest(nil);
- Response.ResponseText := ReadLn;
- if Length(Response.ResponseText) = 0 then begin
- Response.ResponseText := 'HTTP/1.0 200 OK'; // Support for HTTP responses whithout Status line and headers
- Response.Connection := 'close';
- end
- else begin
- RetrieveHeaders;
- ProcessCookies(LLocalHTTP.Request, LLocalHTTP.Response);
- end;
- if Response.ResponseCode = 200 then
- begin
- // Connection established
- (IOHandler as TIdSSLIOHandlerSocket).PassThrough := false;
- break;
- end
- else begin
- ProcessResponse;
- end;
- until false;
- except
- raise;
- // TODO: Add property that will contain the error messages.
- end;
- finally
- LLocalHTTP.Response.ContentStream.Free;
- LLocalHTTP.Free;
- end;
- end;
- end
- else begin
- CheckAndConnect(AResponse);
- end;
- FHTTPProto.BuildAndSendRequest(URL);
- if (ARequest.Method in [hmPost, hmPut]) then
- begin
- WriteStream(ARequest.Source, True, false);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement