2 * Copyright 2010-2017 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Christophe Huriaux, c.huriaux@gmail.com
7 * Adrien Destugues, pulkomandy@pulkomandy.tk
11 #include <HttpResult.h>
18 BHttpResult::BHttpResult(const BUrl
& url
)
27 BHttpResult::BHttpResult(BMessage
* archive
)
30 fUrl(archive
->FindString("http:url")),
32 fStatusCode(archive
->FindInt32("http:statusCode"))
34 fStatusString
= archive
->FindString("http:statusString");
37 archive
->FindMessage("http:headers", &headers
);
38 fHeaders
.PopulateFromArchive(&headers
);
42 BHttpResult::BHttpResult(const BHttpResult
& other
)
45 fHeaders(other
.fHeaders
),
46 fStatusCode(other
.fStatusCode
),
47 fStatusString(other
.fStatusString
)
52 BHttpResult::~BHttpResult()
57 // #pragma mark Result parameters modifications
61 BHttpResult::SetUrl(const BUrl
& url
)
67 // #pragma mark Result parameters access
71 BHttpResult::Url() const
78 BHttpResult::ContentType() const
80 return Headers()["Content-Type"];
85 BHttpResult::Length() const
87 const char* length
= Headers()["Content-Length"];
95 BHttpResult::Headers() const
102 BHttpResult::StatusCode() const
109 BHttpResult::StatusText() const
111 return fStatusString
;
115 // #pragma mark Result tests
119 BHttpResult::HasHeaders() const
121 return fHeaders
.CountHeaders() > 0;
125 // #pragma mark Overloaded members
129 BHttpResult::operator=(const BHttpResult
& other
)
135 fHeaders
= other
.fHeaders
;
136 fStatusCode
= other
.fStatusCode
;
137 fStatusString
= other
.fStatusString
;
144 BHttpResult::Archive(BMessage
* target
, bool deep
) const
146 status_t result
= BUrlResult::Archive(target
, deep
);
150 target
->AddString("http:url", fUrl
);
151 target
->AddInt32("http:statusCode", fStatusCode
);
152 target
->AddString("http:statusString", fStatusString
);
155 fHeaders
.Archive(&headers
);
156 target
->AddMessage("http:headers", &headers
);
162 /*static*/ BArchivable
*
163 BHttpResult::Instantiate(BMessage
* archive
)
165 if (!validate_instantiation(archive
, "BHttpResult"))
168 return new BHttpResult(archive
);