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 { 27 public: 28 // Constructors & Destructor 29 BHttpSession(); 30 BHttpSession(const BHttpSession&) noexcept; 31 BHttpSession(BHttpSession&&) noexcept = delete; 32 ~BHttpSession() noexcept; 33 34 // Assignment operators 35 BHttpSession& operator=(const BHttpSession&) noexcept; 36 BHttpSession& operator=(BHttpSession&&) noexcept = delete; 37 38 // Requests 39 BHttpResult Execute(BHttpRequest&& request, 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 { HttpStatus = '_HST', HttpFields = '_HHF', CertificateError = '_CER', HttpRedirect = '_HRE' }; 58 } 59 60 61 namespace UrlEventData { 62 extern const char* HttpStatusCode; 63 extern const char* SSLCertificate; 64 extern const char* SSLMessage; 65 extern const char* HttpRedirectUrl; 66 } // namespace UrlEventData 67 68 } // namespace Network 69 70 } // namespace BPrivate 71 72 #endif // _B_HTTP_SESSION_H_ 73