Expose details/protocol for current connection via BayeuxContext #701

Closed
giantninja opened this Issue Jan 13, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@giantninja

Currently the details that can be assertained during a handshake, via:

SecurityPolicy.canHandshake(BayeuxServer server, ServerSession session, ServerMessage message)

are limited to basic info like the IP address, port, scheme and transport:

String ip = server.getContext().getLocalAddress().getAddress().getHostAddress();
Integer port = server.getContext().getLocalAddress().getPort();
String scheme = server.getContext().getURL().split(":")[0];
String transport = server.getCurrentTransport().getName();

It would be useful to expose other useful connection information like the protocol in use. For example, if http2 is being used, there isn't currently a way to get that information from the objects exposed to the canHandshake() method, since http2 will most likely be long-polling transport with a scheme of https but that is the same details as a http 1.1 long-polling over https.

@sbordet

This comment has been minimized.

Show comment
Hide comment
@sbordet

sbordet Apr 26, 2017

Member

As a workaround, what you can do is to install a Servlet Filter where you extract the protocol version from the request and store it as a request attribute:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String protocol = request.getProtocol();
    request.setAttribute("protocol", protocol);
    chain.doFilter(request, response);
}

Then from CometD you can access that via BayeuxContext.getRequestAttribute("protocol").

Unfortunately adding a new method to BayeuxContext is an API change that we only do in major/minor version updates, but not micro version updates (so it will be in 3.2 or 4.0).

Member

sbordet commented Apr 26, 2017

As a workaround, what you can do is to install a Servlet Filter where you extract the protocol version from the request and store it as a request attribute:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String protocol = request.getProtocol();
    request.setAttribute("protocol", protocol);
    chain.doFilter(request, response);
}

Then from CometD you can access that via BayeuxContext.getRequestAttribute("protocol").

Unfortunately adding a new method to BayeuxContext is an API change that we only do in major/minor version updates, but not micro version updates (so it will be in 3.2 or 4.0).

@sbordet sbordet added this to the 4.0.0 milestone May 3, 2017

sbordet added a commit that referenced this issue Oct 13, 2017

Fixes #701 - Expose details/protocol for current connection via Baye…
…uxContext.

Added getProtocol(), getContextPath() and isSecure().

@sbordet sbordet closed this Oct 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment