Reintroduce BUrlResult and add BDataRequest
* BUrlResult is back, with ContentType and Length methods. * BHttpResult subclasses it and use HTTP header fields to implement those * Introduce BDataRequest for "data" URIs. These embed the data inside the URI, either as plaintext or base64 encoded.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2013 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Adrien Destugues, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _B_DATA_REQUEST_H_
|
||||
#define _B_DATA_REQUEST_H_
|
||||
|
||||
|
||||
#include <UrlRequest.h>
|
||||
|
||||
|
||||
class BDataRequest: public BUrlRequest {
|
||||
public:
|
||||
BDataRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
const BUrlResult& Result() const;
|
||||
private:
|
||||
status_t _ProtocolLoop();
|
||||
private:
|
||||
BUrlResult fResult;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -19,10 +19,13 @@ public:
|
||||
BUrlContext* context = NULL);
|
||||
virtual ~BFileRequest();
|
||||
|
||||
const BUrlResult& Result() const;
|
||||
void SetDisableListener(bool disable);
|
||||
|
||||
private:
|
||||
status_t _ProtocolLoop();
|
||||
private:
|
||||
BUrlResult fResult;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
const ssize_t size = -1);
|
||||
void AdoptHeaders(BHttpHeaders* const headers);
|
||||
|
||||
const BHttpResult& Result() const;
|
||||
const BUrlResult& Result() const;
|
||||
const char* StatusString(status_t threadStatus) const;
|
||||
|
||||
static bool IsInformationalStatusCode(int16 code);
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_URL_RESULT_H_
|
||||
#define _B_URL_RESULT_H_
|
||||
#ifndef _B_HTTP_RESULT_H_
|
||||
#define _B_HTTP_RESULT_H_
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <HttpHeaders.h>
|
||||
#include <String.h>
|
||||
#include <Url.h>
|
||||
#include <UrlResult.h>
|
||||
|
||||
|
||||
class BUrlRequest;
|
||||
|
||||
|
||||
class BHttpResult {
|
||||
class BHttpResult: public BUrlResult {
|
||||
friend class BHttpRequest;
|
||||
|
||||
public:
|
||||
@@ -30,6 +30,8 @@ public:
|
||||
|
||||
// Result parameters access
|
||||
const BUrl& Url() const;
|
||||
BString ContentType() const;
|
||||
size_t Length() const;
|
||||
|
||||
// HTTP-Specific stuff
|
||||
const BHttpHeaders& Headers() const;
|
||||
@@ -45,7 +47,6 @@ public:
|
||||
private:
|
||||
BUrl fUrl;
|
||||
|
||||
// TODO: HTTP specific stuff should not live here.
|
||||
BHttpHeaders fHeaders;
|
||||
int32 fStatusCode;
|
||||
BString fStatusString;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <Url.h>
|
||||
#include <UrlContext.h>
|
||||
#include <UrlProtocolListener.h>
|
||||
#include <UrlResult.h>
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
@@ -43,6 +44,7 @@ public:
|
||||
status_t Status() const;
|
||||
virtual const char* StatusString(status_t threadStatus)
|
||||
const;
|
||||
virtual const BUrlResult& Result() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_URL_RESULT_H_
|
||||
#define _B_URL_RESULT_H_
|
||||
|
||||
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BUrlResult {
|
||||
public:
|
||||
virtual ~BUrlResult();
|
||||
void SetContentType(BString contentType);
|
||||
void SetLength(size_t length);
|
||||
|
||||
virtual BString ContentType() const;
|
||||
virtual size_t Length() const;
|
||||
|
||||
private:
|
||||
BString fContentType;
|
||||
BString fCharset;
|
||||
size_t fLength;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user