My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef flagNOSSL

#include "WebSSL.h"

NAMESPACE_UPP

extern bool HttpClient_Trace__;

#ifdef _DEBUG
#define LLOG(x) if(HttpClient_Trace__) RLOG(x); else;
#else
#define LLOG(x)
#endif

HttpsClient::HttpsClient()
{
secure = true;
}

bool HttpsClient::ProxyConnect()
{
if(use_proxy) {
int start_time = msecs();
int end_time = msecs() + timeout_msecs;
while(!socket.PeekWrite(1000)) {
int time = msecs();
if(time >= end_time) {
error = NFormat(t_("%s:%d: connecting to host timed out"), socket_host, socket_port);
Close();
return false;
}
}
String host_port = host;
if(port)
host_port << ':' << port;
else
host_port << ":443";
String request;
request << "CONNECT " << host_port << " HTTP/1.1\r\n"
<< "Host: " << host_port << "\r\n";
if(!IsNull(proxy_username))
request << "Proxy-Authorization: Basic "
<< Base64Encode(proxy_username + ':' + proxy_password) << "\r\n";
request << "\r\n";
LLOG(request);
int written = 0;
while(msecs() - end_time < 0) {
int nwrite = socket.WriteWait(request.GetIter(written), min(request.GetLength() - written, 1000), 1000);
if(socket.IsError()) {
error = Socket::GetErrorText();
Close();
return false;
}
if((written += nwrite) >= request.GetLength())
break;
}
if(written < request.GetLength()) {
error = NFormat(t_("%s:%d: timed out sending request to server"), host, port);
Close();
return false;
}
String line = ReadUntilProgress('\n', start_time, end_time, false);
LLOG("P< " << line);
if(socket.IsError()) {
error = Socket::GetErrorText();
Close();
return false;
}
if(!line.StartsWith("HTTP") || line.Find(" 2") < 0) {
error = "Invalid proxy reply: " + line;
Close();
return false;
}
while(line.GetCount()) {
line = ReadUntilProgress('\n', start_time, end_time, false);
if(*line.Last() == '\r')
line.Trim(line.GetCount() - 1);
LLOG("P< " << line << " len " << line.GetCount());
if(socket.IsError()) {
error = Socket::GetErrorText();
Close();
return false;
}
}
use_proxy = false;
while(!socket.PeekWrite(1000)) {
int time = msecs();
if(time >= end_time) {
error = NFormat(t_("%s:%d: connecting to host timed out"), socket_host, socket_port);
Close();
return false;
}
}
}
return true;
}

bool HttpsClient::IsSecure()
{
return secure;
}

bool HttpsClient::CreateClientSocket()
{
if(!secure)
return HttpClient::CreateClientSocket();
if(!ssl_context) {
ssl_context = new SSLContext;
if(!ssl_context->Create(const_cast<SSL_METHOD *>(SSLv3_client_method()))) {
error = t_("Error creating SSL context.");
return false;
}
}
if(!SSLClientSocketUnsecured(socket, *ssl_context, socket_host,
socket_port ? socket_port : DEFAULT_HTTPS_PORT, true, NULL, 0, false)) {
error = Socket::GetErrorText();
return false;
}
socket.Linger(0);
if(!ProxyConnect())
return false;
SSLSecureSocket(socket);
return true;
}

END_UPP_NAMESPACE

#endif

Change log

r4798 by cxl on Apr 17, 2012   Diff
*Core: Fixed msecs issues
Go to: 
Project members, sign in to write a code review

Older revisions

r4783 by cxl on Apr 14, 2012   Diff
Core/SSL: SSL support for TcpSocket
and HttpRequest finally working...
r4361 by cxl on Jan 5, 2012   Diff
*Web/SSL: HttpsClient now correctly
uses CONNECT for proxy
r3553 by rylek on Jun 22, 2011   Diff
*Web: bug fix - default HTTPS port
number
*Web: added ugly hack to get rid of
SSL memory leaks
All revisions of this file

File info

Size: 3164 bytes, 128 lines
Powered by Google Project Hosting