capture path/uri when connecting, and pass it back through callbacks in the openInfo member
This commit is contained in:
@ -40,9 +40,8 @@ namespace ix
|
||||
[this](uint16_t code, const std::string& reason, size_t wireSize)
|
||||
{
|
||||
_onMessageCallback(WebSocket_MessageType_Close, "", wireSize,
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketCloseInfo(code, reason),
|
||||
WebSocketHttpHeaders());
|
||||
WebSocketErrorInfo(), WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo(code, reason));
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -119,8 +118,9 @@ namespace ix
|
||||
}
|
||||
|
||||
_onMessageCallback(WebSocket_MessageType_Open, "", 0,
|
||||
WebSocketErrorInfo(), WebSocketCloseInfo(),
|
||||
status.headers);
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo(status.uri, status.headers),
|
||||
WebSocketCloseInfo());
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -138,8 +138,9 @@ namespace ix
|
||||
}
|
||||
|
||||
_onMessageCallback(WebSocket_MessageType_Open, "", 0,
|
||||
WebSocketErrorInfo(), WebSocketCloseInfo(),
|
||||
status.headers);
|
||||
WebSocketErrorInfo(),
|
||||
WebSocketOpenInfo(status.uri, status.headers),
|
||||
WebSocketCloseInfo());
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -184,8 +185,8 @@ namespace ix
|
||||
connectErr.reason = status.errorStr;
|
||||
connectErr.http_status = status.http_status;
|
||||
_onMessageCallback(WebSocket_MessageType_Error, "", 0,
|
||||
connectErr, WebSocketCloseInfo(),
|
||||
WebSocketHttpHeaders());
|
||||
connectErr, WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo());
|
||||
|
||||
std::this_thread::sleep_for(duration);
|
||||
}
|
||||
@ -240,8 +241,8 @@ namespace ix
|
||||
webSocketErrorInfo.decompressionError = decompressionError;
|
||||
|
||||
_onMessageCallback(webSocketMessageType, msg, wireSize,
|
||||
webSocketErrorInfo, WebSocketCloseInfo(),
|
||||
WebSocketHttpHeaders());
|
||||
webSocketErrorInfo, WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo());
|
||||
|
||||
WebSocket::invokeTrafficTrackerCallback(msg.size(), true);
|
||||
});
|
||||
|
@ -41,6 +41,20 @@ namespace ix
|
||||
WebSocket_MessageType_Pong = 5
|
||||
};
|
||||
|
||||
struct WebSocketOpenInfo
|
||||
{
|
||||
std::string uri;
|
||||
WebSocketHttpHeaders headers;
|
||||
|
||||
WebSocketOpenInfo(const std::string& u = std::string(),
|
||||
const WebSocketHttpHeaders& h = WebSocketHttpHeaders())
|
||||
: uri(u)
|
||||
, headers(h)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
struct WebSocketCloseInfo
|
||||
{
|
||||
uint16_t code;
|
||||
@ -59,8 +73,9 @@ namespace ix
|
||||
const std::string&,
|
||||
size_t wireSize,
|
||||
const WebSocketErrorInfo&,
|
||||
const WebSocketCloseInfo&,
|
||||
const WebSocketHttpHeaders&)>;
|
||||
const WebSocketOpenInfo&,
|
||||
const WebSocketCloseInfo&)>;
|
||||
|
||||
using OnTrafficTrackerCallback = std::function<void(size_t size, bool incoming)>;
|
||||
|
||||
class WebSocket
|
||||
|
@ -380,7 +380,7 @@ namespace ix
|
||||
}
|
||||
}
|
||||
|
||||
return WebSocketInitResult(true, status, "", headers);
|
||||
return WebSocketInitResult(true, status, "", headers, path);
|
||||
}
|
||||
|
||||
WebSocketInitResult WebSocketHandshake::serverHandshake(int fd)
|
||||
@ -491,6 +491,6 @@ namespace ix
|
||||
return WebSocketInitResult(false, 0, std::string("Failed sending response to ") + remote);
|
||||
}
|
||||
|
||||
return WebSocketInitResult(true, 200, "", headers);
|
||||
return WebSocketInitResult(true, 200, "", headers, uri);
|
||||
}
|
||||
}
|
||||
|
@ -26,16 +26,19 @@ namespace ix
|
||||
int http_status;
|
||||
std::string errorStr;
|
||||
WebSocketHttpHeaders headers;
|
||||
std::string uri;
|
||||
|
||||
WebSocketInitResult(bool s = false,
|
||||
int status = 0,
|
||||
const std::string& e = std::string(),
|
||||
WebSocketHttpHeaders h = WebSocketHttpHeaders())
|
||||
WebSocketHttpHeaders h = WebSocketHttpHeaders(),
|
||||
const std::string& u = std::string())
|
||||
{
|
||||
success = s;
|
||||
http_status = status;
|
||||
errorStr = e;
|
||||
headers = h;
|
||||
uri = u;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4,11 +4,6 @@
|
||||
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
// TODO
|
||||
// pass to callback PATH
|
||||
// pass connection success too to callback
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility> // pair
|
||||
|
Reference in New Issue
Block a user