/
showHttp.cpp
74 lines (61 loc) · 2.33 KB
/
showHttp.cpp
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
/*
Copyright 2012 Aish Raj Dahal dahalaishraj@gmail.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "showHttp.h"
#include <kdebug.h>
showHttp::showHttp()
{
output();
}
showHttp::~showHttp()
{
}
void showHttp::output()
{
KIO::SimpleJob *job;
//job = KIO::get(KUrl("http://download.services.openoffice.org/files/stable/3.3.0/OOo-SDK_3.3.0_Linux_x86-64_install-deb_en-US.tar.gz"));
job = KIO::get(KUrl("http://download.services.openoffice.org/files/du.list"));
job->addMetaData("PropagateHttpHeader","true");
job->setRedirectionHandlingEnabled(false);//In case this is set true of left to the defaults the URL is being redirected.
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
}
void showHttp::slotResult(KJob* kjob)
{
KIO::Job* job = qobject_cast<KIO::Job*>(kjob);
const QString httpHeaders = job ? job->queryMetaData("HTTP-Headers") : QString();
//qDebug() << "HTTP HEADERS:" << httpHeaders;
parseHeaders(httpHeaders);
}
void showHttp::parseHeaders(const QString& httpHeader)
{
QString trimedHeader = httpHeader.mid(httpHeader.indexOf('\n') + 1).trimmed();
foreach (QString line, trimedHeader.split('\n')) {
int colon = line.indexOf(':');
QString headerName = line.left(colon).trimmed();
QString headerValue = line.mid(colon + 1).trimmed();
m_headerInfo.insertMulti(headerName,headerValue);
}
//Testing code
QList<QString> mirror_values = m_headerInfo.values("link");
QList<QString> digest_values = m_headerInfo.values("digest");
qDebug() << "The miror values are";
for ( int i = 0; i < mirror_values.size(); i++) {
qDebug() << mirror_values.at(i);
}
qDebug() << "The hashes are" ;
foreach ( QString digest_val, digest_values) {
qDebug() << digest_val ;
}
exit(0);
}
#include "showHttp.moc"