OpenSSL - SSL_write problem
I write a little HTTPS client in C and I have a problem with the SSL_write function. Three tests to illustrate my problem:
#define HEADERS1 "GET / HTTP/1.1\r\n"
#define HEADERS2 "Host: www.example.com\r\n"
#define HEADERS3 "User-Agent: OpenSSL\r\n"
#define HEADERS4 "\r\n"
#define HEADERS "GET / HTTP/1.1\r\nHost: www.example.com\r\nUser-Agent: OpenSSL\r\n\r\n"
Test 1:
SSL_write(ssl,HEADERS,strlen(HEADERS));
Success: The server correctly return the /index.html ressource with the HTTP/1.1 200 Code.
Test 2:
SSL_write(ssl,HEADERS1,strlen(HEADERS1));
SSL_write(ssl,HEADERS2,strlen(HEADERS2));
SSL_write(ssl,HEADERS3,strlen(HEADERS3));
SSL_write(ssl,HEADERS4,strlen(HEADERS4));
Failure: The server doesn't return anything. All SSL_write functions don't return ERROR but my application is locked on SSL_read because the destination server give no content... and no headers :(
Test 3:
SSL_write(ssl,HEADERS1,strlen(HEADERS1));
SSL_write(ssl,HEADERS2,strlen(HEADERS2));
SSL_write(ssl,HEADERS4,strlen(HEADERS4));
Success: The server correctly return the /index.html ressource with the HTTP/1.1 200 Cod开发者_开发百科e.
Is there a particular limitation on the number of times I can call SSL_write to send headers? Very strange...
Thanks you very much !
Ok, so my problem persits but I have more details:
IISS-SSL => All tests success.
Apache-SSL => All tests success.
Nginx-SSL => All tests success.
LightHTTPD-SSL => Test 2 failure.
I don't understand why only LightHTTPD don't understand my request...
For SSL_Write() operation, correct way should be after SSL_Write call , check on the message returned. If it is SSL_WANT_READ, then give some small amount of time for it to read.
Doing Continuous write operation with checking return value may be successful , but it is not safe, as you will not be sure of the data you wrote reached server and server read it completely.
This in turn may affect other SSL_write operations.
精彩评论