xref: /haiku/headers/private/netservices2/HttpSession.h (revision 27196c40686c30b134952e9c1807f9f8b29be36d)
1 /*
2  * Copyright 2022 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _B_HTTP_SESSION_H_
7 #define _B_HTTP_SESSION_H_
8 
9 #include <memory>
10 
11 #include <ExclusiveBorrow.h>
12 #include <Messenger.h>
13 
14 class BUrl;
15 
16 
17 namespace BPrivate {
18 
19 namespace Network {
20 
21 class BHttpRequest;
22 class BHttpResult;
23 
24 
25 class BHttpSession {
26 public:
27 	// Constructors & Destructor
28 							BHttpSession();
29 							BHttpSession(const BHttpSession&) noexcept;
30 							BHttpSession(BHttpSession&&) noexcept = delete;
31 							~BHttpSession() noexcept;
32 
33 	// Assignment operators
34 	BHttpSession&			operator=(const BHttpSession&) noexcept;
35 	BHttpSession&			operator=(BHttpSession&&) noexcept = delete;
36 
37 	// Requests
38 	BHttpResult				Execute(BHttpRequest&& request,
39 								BBorrow<BDataIO> target = nullptr,
40 								BMessenger observer = BMessenger());
41 	void					Cancel(int32 identifier);
42 	void					Cancel(const BHttpResult& request);
43 
44 	// Concurrency limits
45 	void					SetMaxConnectionsPerHost(size_t maxConnections);
46 	void					SetMaxHosts(size_t maxConnections);
47 
48 private:
49 	struct Redirect;
50 	class Request;
51 	class Impl;
52 	std::shared_ptr<Impl>	fImpl;
53 };
54 
55 
56 namespace UrlEvent {
57 	enum {
58 		HttpStatus = '_HST',
59 		HttpFields = '_HHF',
60 		CertificateError = '_CER',
61 		HttpRedirect = '_HRE'
62 	};
63 }
64 
65 
66 namespace UrlEventData {
67 	extern const char* HttpStatusCode;
68 	extern const char* SSLCertificate;
69 	extern const char* SSLMessage;
70 	extern const char* HttpRedirectUrl;
71 }
72 
73 } // namespace Network
74 
75 } // namespace BPrivate
76 
77 #endif // _B_HTTP_SESSION_H_
78