Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
On failure to send HTTP request to an existing session, retry
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed May 22, 2013
1 parent e178b2f commit fe85faa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
31 changes: 23 additions & 8 deletions http.c
Expand Up @@ -835,20 +835,15 @@ static int do_https_request(struct openconnect_info *vpninfo, const char *method
{
struct oc_text_buf *buf;
int result, buflen;
int rq_retry;

retry:
redirected:
vpninfo->redirect_type = REDIR_TYPE_NONE;

if (*form_buf) {
free(*form_buf);
*form_buf = NULL;
}
if (openconnect_open_https(vpninfo)) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to open HTTPS connection to %s\n"),
vpninfo->hostname);
return -EINVAL;
}

/*
* It would be nice to use cURL for this, but we really need to guarantee
Expand Down Expand Up @@ -884,7 +879,27 @@ static int do_https_request(struct openconnect_info *vpninfo, const char *method
if (buf_error(buf))
return buf_free(buf);

retry:
if (openconnect_https_connected(vpninfo)) {
/* The session is already connected. If we get a failure on
* *sending* the request, try it again immediately with a new
* connection. */
rq_retry = 1;
} else {
rq_retry = 0;
if (openconnect_open_https(vpninfo)) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to open HTTPS connection to %s\n"),
vpninfo->hostname);
return -EINVAL;
}
}

result = openconnect_SSL_write(vpninfo, buf->data, buf->pos);
if (rq_retry && result < 0) {
openconnect_close_https(vpninfo, 0);
goto retry;
}
buf_free(buf);
if (result < 0)
return result;
Expand All @@ -900,7 +915,7 @@ static int do_https_request(struct openconnect_info *vpninfo, const char *method
if (result == 0) {
if (!fetch_redirect)
return 0;
goto retry;
goto redirected;
}
goto out;
}
Expand Down
5 changes: 5 additions & 0 deletions openconnect-internal.h
Expand Up @@ -410,6 +410,11 @@ int openconnect_sha1(unsigned char *result, void *data, int len);
int openconnect_random(void *bytes, int len);
int openconnect_local_cert_md5(struct openconnect_info *vpninfo,
char *buf);
#if defined(OPENCONNECT_OPENSSL)
#define openconnect_https_connected(_v) ((_v)->https_ssl)
#elif defined (OPENCONNECT_GNUTLS)
#define openconnect_https_connected(_v) ((_v)->https_sess)
#endif

/* mainloop.c */
int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
Expand Down

0 comments on commit fe85faa

Please sign in to comment.