Merge pull request #37 from Lawlieta/master

【修复】 HTTP Location 地址跳转错误
master
朱天龙 (Armink) 7 years ago committed by GitHub
commit c872971c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -379,10 +379,16 @@ static int webclient_connect(struct webclient_session *session, const char *URI)
} }
/* copy host address */ /* copy host address */
if (*req_url) if (req_url)
{ {
session->req_url = web_strdup(req_url); session->req_url = web_strdup(req_url);
} }
else
{
LOG_E("connect failed, resolve request address error.");
rc = -WEBCLIENT_ERROR;
goto __exit;
}
#ifdef WEBCLIENT_USING_TLS #ifdef WEBCLIENT_USING_TLS
if (session->tls_session) if (session->tls_session)
@ -856,8 +862,28 @@ int webclient_get(struct webclient_session *session, const char *URI)
/* relocation */ /* relocation */
if ((resp_status == 302 || resp_status == 301) && location) if ((resp_status == 302 || resp_status == 301) && location)
{ {
char *new_url;
new_url = web_strdup(location);
if (new_url == RT_NULL)
{
return -WEBCLIENT_NOMEM;
}
/* close old client session */
webclient_close(session); webclient_close(session);
return webclient_get(session, location);
/* create new client session by location url */
session = webclient_session_create(WEBCLIENT_HEADER_BUFSZ);
if (session == RT_NULL)
{
return -WEBCLIENT_NOMEM;
}
rc = webclient_get(session, new_url);
web_free(new_url);
return rc;
} }
else if (resp_status != 200) else if (resp_status != 200)
{ {
@ -915,8 +941,28 @@ int webclient_get_position(struct webclient_session *session, const char *URI, i
/* relocation */ /* relocation */
if ((resp_status == 302 || resp_status == 301) && location) if ((resp_status == 302 || resp_status == 301) && location)
{ {
char *new_url;
new_url = web_strdup(location);
if (new_url == RT_NULL)
{
return -WEBCLIENT_NOMEM;
}
/* close old client session */
webclient_close(session); webclient_close(session);
return webclient_get_position(session, location, position);
/* create new client session by location url */
session = webclient_session_create(WEBCLIENT_HEADER_BUFSZ);
if (session == RT_NULL)
{
return -WEBCLIENT_NOMEM;
}
rc = webclient_get(session, new_url);
web_free(new_url);
return rc;
} }
else if (resp_status != 206) else if (resp_status != 206)
{ {

Loading…
Cancel
Save