/*
NETWOX
Network toolbox
Copyright(c) 1999-2006 Laurent Constantin
-----
Main server : http://www.laurentconstantin.com/
Backup servers : http://go.to/laurentconstantin/
http://laurentconstantin.est-la.com/
http://laurentconstantin.free.fr/
http://membres.lycos.fr/lauconstantin/
[my current email address is on the web servers]
-----
This file is part of Netwox.
Netwox is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Netwox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details (http://www.gnu.org/).
------------------------------------------------------------------------
*/
/*-------------------------------------------------------------*/
#include "../../netwox.h"
/*-------------------------------------------------------------*/
static netwib_err netwox_url_download_http(netwox_httpclictx *pctx,
netwib_constbuf *purl,
netwib_bool downloadfile,
netwib_io *pfileio,
netwib_bool obtainsize,
netwib_uint32 *psize,
netwox_httphdr_statuscode *pstatuscode,
netwib_buf *pcontenttype)
{
netwox_httphdr_statuscode statuscode;
netwox_httpcliresphdrs resphdrs;
netwox_httphdr_method method;
netwib_buf *pmsg;
netwib_err ret;
method = NETWOX_HTTPHDR_METHOD_GET;
if (obtainsize) {
method = NETWOX_HTTPHDR_METHOD_HEAD;
}
netwib_er(netwox_httpcliresphdrs_init(&resphdrs));
ret = netwox_httpcli_method(NETWOX_HTTPHDR_METHOD_GET, pctx, purl,
&resphdrs, &statuscode, NULL, pfileio);
if (ret == NETWIB_ERR_OK) {
if (resphdrs.contenttypeset) {
netwib_er(netwib_buf_append_buf(&resphdrs.contenttype, pcontenttype));
}
if (downloadfile) {
if (resphdrs.locationset) {
if (statuscode == NETWOX_HTTPHDR_STATUSCODE_MOVEDPERMANENTLY ||
statuscode == NETWOX_HTTPHDR_STATUSCODE_MOVEDTEMPORARILY) {
netwib_er(netwib_bufpool_buf_init(pctx->pbufpool, &pmsg));
netwib_er(netwib_buf_append_fmt(pmsg, "
Added by the spider : new location.