PIHTTPServer basic auth works
This commit is contained in:
@@ -16,3 +16,47 @@ const char * PIHTTP::methodName(Method m) {
|
||||
};
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable & PIHTTP::MessageMutable::addHeader(const PIString & header, const PIString & value) {
|
||||
m_headers[header] = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable & PIHTTP::MessageMutable::setMethod(Method m) {
|
||||
m_method = m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable & PIHTTP::MessageMutable::setCode(Code c) {
|
||||
m_code = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable & PIHTTP::MessageMutable::setPath(PIString p) {
|
||||
m_path = std::move(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable & PIHTTP::MessageMutable::setBody(PIByteArray b) {
|
||||
m_body = std::move(b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable PIHTTP::MessageMutable::fromCode(Code c) {
|
||||
PIHTTP::MessageMutable ret;
|
||||
ret.setCode(c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIHTTP::MessageMutable PIHTTP::MessageMutable::fromMethod(Method m) {
|
||||
PIHTTP::MessageMutable ret;
|
||||
ret.setMethod(m);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,18 @@ protected:
|
||||
|
||||
class PIP_EXPORT MessageMutable: public MessageConst {
|
||||
public:
|
||||
void setMethod(PIHTTP::Method m) { m_method = m; }
|
||||
void setCode(PIHTTP::Code c) { m_code = c; }
|
||||
void setPath(PIString p) { m_path = std::move(p); }
|
||||
void setBody(PIByteArray b) { m_body = std::move(b); }
|
||||
MessageMutable & setMethod(PIHTTP::Method m);
|
||||
MessageMutable & setCode(PIHTTP::Code c);
|
||||
MessageMutable & setPath(PIString p);
|
||||
MessageMutable & setBody(PIByteArray b);
|
||||
const PIMap<PIString, PIString> & headers() const { return m_headers; }
|
||||
const PIMap<PIString, PIString> & arguments() const { return m_arguments; }
|
||||
PIMap<PIString, PIString> & headers() { return m_headers; }
|
||||
PIMap<PIString, PIString> & arguments() { return m_arguments; }
|
||||
void addHeader(const PIString & header, const PIString & value) { m_headers[header] = value; }
|
||||
MessageMutable & addHeader(const PIString & header, const PIString & value);
|
||||
void removeHeader(const PIString & header) { m_headers.remove(header); }
|
||||
static MessageMutable fromCode(PIHTTP::Code c);
|
||||
static MessageMutable fromMethod(PIHTTP::Method m);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -32,15 +32,25 @@ public:
|
||||
bool isListen() const;
|
||||
void stop();
|
||||
|
||||
void enableBasicAuth() { setBasicAuthEnabled(true); }
|
||||
void disableBasicAuth() { setBasicAuthEnabled(false); }
|
||||
void setBasicAuthEnabled(bool yes) { use_basic_auth = yes; }
|
||||
bool isBasicAuthEnabled() const { return use_basic_auth; }
|
||||
void setBasicAuthRealm(const PIString & r) { realm = r; }
|
||||
|
||||
void setRequestCallback(std::function<PIHTTP::MessageMutable(const PIHTTP::MessageConst &)> c) { callback = c; }
|
||||
void setBasicAuthCallback(std::function<bool(const PIString &, const PIString &)> c) { callback_auth = c; }
|
||||
|
||||
private:
|
||||
static void addFixedHeaders(PIHTTP::MessageMutable & msg);
|
||||
PRIVATE_DECLARATION(PIP_HTTP_SERVER_EXPORT)
|
||||
|
||||
PIByteArray favicon;
|
||||
PIString realm;
|
||||
PIMap<Option, PIVariant> opts;
|
||||
std::function<PIHTTP::MessageMutable(const PIHTTP::MessageConst &)> callback;
|
||||
std::function<bool(const PIString &, const PIString &)> callback_auth;
|
||||
std::atomic_bool use_basic_auth = {false};
|
||||
PIByteArray mem_key, mem_cert, key_pass;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
void unregisterPath(const PIString & path, PIHTTP::Method method);
|
||||
void unregisterPath(const PIString & path);
|
||||
|
||||
// void registerBasicAuth() {}
|
||||
|
||||
void addReplyHeader(const PIString & name, const PIString & value) { reply_headers[name] = value; }
|
||||
void removeReplyHeader(const PIString & name) { reply_headers.remove(name); }
|
||||
void clearReplyHeaders() { reply_headers.clear(); }
|
||||
|
||||
Reference in New Issue
Block a user