1 // This may look like C code, but it's really -*- C++ -*- 2 /* 3 * Copyright (C) 2008 Emweb bv, Herent, Belgium. 4 * 5 * See the LICENSE file for terms of use. 6 */ 7 #ifndef HTTP_HTTP_REQUEST_H_ 8 #define HTTP_HTTP_REQUEST_H_ 9 10 #include <sstream> 11 12 #include "WebRequest.h" 13 #include "WtReply.h" 14 #include "Wt/Http/Message.h" 15 16 namespace http { 17 namespace server { 18 19 class HTTPRequest final : public Wt::WebResponse 20 { 21 public: 22 HTTPRequest(WtReplyPtr wtReply, const Wt::EntryPoint *entryPoint); 23 void reset(WtReplyPtr reply, const Wt::EntryPoint *entryPoint); 24 bool done() const; 25 26 virtual void flush(ResponseState state, const WriteCallback& callback) override; 27 virtual void readWebSocketMessage(const ReadCallback& callback) override; 28 virtual bool webSocketMessagePending() const override; 29 virtual bool detectDisconnect(const DisconnectCallback& callback) override; 30 in()31 virtual std::istream& in() override { return reply_->in(); } out()32 virtual std::ostream& out() override { return reply_->out(); } err()33 virtual std::ostream& err() override { return std::cerr; } 34 35 virtual void setStatus(int status) override; 36 virtual void setContentLength(::int64_t length) override; 37 38 virtual void addHeader(const std::string& name, const std::string& value) override; 39 virtual void setContentType(const std::string& value) override; 40 virtual void setRedirect(const std::string& url) override; 41 42 virtual const char *contentType() const override; 43 virtual ::int64_t contentLength() const override; 44 45 virtual const char *envValue(const char *name) const override; 46 virtual const char *headerValue(const char *name) const override; 47 virtual std::vector<Wt::Http::Message::Header> headers() const override; 48 virtual const std::string& serverName() const override; 49 virtual const std::string& serverPort() const override; 50 virtual const std::string& scriptName() const override; 51 virtual const char *requestMethod() const override; 52 virtual const std::string& queryString() const override; 53 virtual const std::string& pathInfo() const override; 54 virtual const std::string& remoteAddr() const override; 55 virtual const char *urlScheme() const override; 56 bool isSynchronous() const; 57 virtual std::unique_ptr<Wt::WSslInfo> sslInfo(const Wt::Configuration & conf) const override; 58 virtual const std::vector<std::pair<std::string, std::string> > &urlParams() const override; 59 60 private: 61 WtReplyPtr reply_; 62 mutable std::string serverPort_; 63 mutable std::vector<std::string> s_; 64 65 #ifdef HTTP_WITH_SSL 66 // Extracts SSL info from internal Wt-specific base64-encoded JSON implementation, 67 // used for Wt's own reverse proxy (dedicated session processes). 68 std::unique_ptr<Wt::WSslInfo> sslInfoFromJson() const; 69 #endif // HTTP_WITH_SSL 70 // Extract SSL info from X-SSL-Client-* headers. Can be used when Wt is behind an SSL-terminating 71 // proxy like nginx or Apache (HAProxy's headers are not currently supported). 72 std::unique_ptr<Wt::WSslInfo> sslInfoFromHeaders() const; 73 74 const char *cstr(const buffer_string& bs) const; 75 76 static const std::string empty_; 77 }; 78 79 } 80 } 81 82 #endif // HTTP_HTTP_REQUEST_H_ 83