Commit 04554f36 authored by jan.koester's avatar jan.koester
Browse files

peer addr support

parent f89a54a2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -4706,6 +4706,14 @@ size_t libhttppp::HttpRequest::getMaxUploadSize(){
  return _MaxUploadSize;
}

void libhttppp::HttpRequest::setPeerAddress(const std::string &addr){
  _peerAddress = addr;
}

const std::string &libhttppp::HttpRequest::getPeerAddress() const{
  return _peerAddress;
}

bool libhttppp::HttpRequest::isMobile(){
  for(HeaderData *curdat=getfirstHeaderData(); curdat; curdat=curdat->nextHeaderData()){
    if(curdat->getkey()=="user-agent"){
+14 −0
Original line number Diff line number Diff line
@@ -491,6 +491,19 @@ namespace libhttppp {
    /*mobilphone switch*/
    bool isMobile();

    /* Per-stream HTTP/2 and HTTP/3 requests are dispatched on a fresh,
     * unconnected HttpRequest (see HttpEvent::_dispatchH2Stream/H3 in
     * httpd.cpp) since one physical connection multiplexes many streams --
     * that object's `slots` is always empty, so callers that need the real
     * peer address (e.g. a reverse proxy building X-Forwarded-For) can't
     * get it from `con::slots` the way an HTTP/1.1 request's connection
     * object provides it. The dispatcher stashes the address it already
     * has (from the real connection's socket) here before calling
     * RequestEvent(); callers should prefer this over slots[0].csock when
     * it's non-empty. */
    void               setPeerAddress(const std::string &addr);
    const std::string &getPeerAddress() const;

    /*Client methods*/
    void              setRequestType(int req);
    void              setRequestURL(const std::string &url);
@@ -519,6 +532,7 @@ namespace libhttppp {
    mutable std::string _cachedRequest;
    mutable std::string _cachedRequestVersion;
    mutable std::string _cachedHost;
    std::string          _peerAddress;

    // HTTP/2 and HTTP/3 protocol state (managed by HttpEvent).
    // All H2-specific mutable state lives in a heap-allocated struct so
+12 −0
Original line number Diff line number Diff line
@@ -456,6 +456,18 @@ bool libhttppp::HttpEvent::_dispatchH2Stream(HttpRequest &cureq,
    HttpRequest &tempreq = *tempreq_ptr;
    tempreq.parseH2(decoded, sid);

    // tempreq is a fresh, unconnected HttpRequest (one physical connection
    // multiplexes many H2 streams, each dispatched on its own temporary
    // object) -- its own `slots` is always empty, so a caller building
    // X-Forwarded-For from tempreq alone (the only object RequestEvent()
    // sees) would see no peer address at all. Carry over the real one from
    // cureq, the actual connection, while we still have both in scope.
    if (!cureq.slots.empty() && cureq.slots[0].csock) {
        std::string peerAddr;
        cureq.slots[0].csock->getAddress(peerAddr);
        tempreq.setPeerAddress(peerAddr);
    }

    // Log dispatch for debugging
    std::string dbg_path;
    for (auto &hf : decoded) {