Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpServerRoutes.ws() javadoc is not in line with WebsocketInbound capabilities #191

Closed
akiraly opened this issue Oct 22, 2017 · 6 comments
Milestone

Comments

@akiraly
Copy link
Contributor

akiraly commented Oct 22, 2017

HttpServerRoutes.ws() says: Additional regex matching is available e.g. "/test/{param}". Params are resolved using HttpServerRequest.param(CharSequence). This is not correct (at least not this way).

  1. The ws() methods work with WebsocketInbound and not with HttpServerRequest.

  2. WebsocketInbound does not extend HttpServerRequest and does not have any of the param* methods that HttpServerRequest has.

  3. The implementation of WebsocketInbound: HttpServerWSOperations does have these methods because it inherits them from HttpServerOperations (which is also the implementation of HttpServerRequest).

So IMHO either this part should be removed from the ws() javadocs or the param* method declarations should be moved from HttpServerRequest to an interface which then could be extended by both HttpServerRequest and WebsocketInbound.

@violetagg violetagg added this to the 0.7.2.RELEASE milestone Oct 23, 2017
@violetagg
Copy link
Member

Hi,

You are able to do the following:

	@Test
	public void webSocketTest() {
		NettyContext server =
				HttpServer.create(0)
				          .newRouter(r -> r.ws("/test/{param}",
				                               (in, out) -> out.sendString(Mono.just("hello"))))
				          .block(Duration.ofSeconds(5));

		HttpClient client = HttpClient.create("localhost", server.address().getPort());

		Flux<String> response =
		    client.ws("/test/World")
		          .flatMapMany(res -> res.receive()
		                                 .asString());

		StepVerifier.create(response)
		            .expectNextMatches(str -> "hello".equals(str))
		            .expectComplete()
		            .verify(Duration.ofSeconds(30));

		server.dispose();
	}

So can you clarify your request?

Thanks,
Violeta

@akiraly
Copy link
Contributor Author

akiraly commented Oct 30, 2017

Hi @violetagg,

How do you get the value of {param}? Let's say you wanted to echo back the value of {param} instead of the constant "hello". How do you do that?

Thanks,
Attila

@violetagg
Copy link
Member

yes with this shortcut you will not be able to access the parameters, however you still can use route in order to do that:
https://github.com/reactor/reactor-netty/blob/master/src/main/java/reactor/ipc/netty/http/server/HttpServerRoutes.java#L269

@akiraly
Copy link
Contributor Author

akiraly commented Oct 30, 2017

That's my point. The javadoc claims we can do that, but we can't. So maybe worth removing this part: Params are resolved using HttpServerRequest.param(CharSequence) from the ws() methods javadoc?

@violetagg
Copy link
Member

actually they are resolved as you can see in the test above and in the source here
https://github.com/reactor/reactor-netty/blob/master/src/main/java/reactor/ipc/netty/http/server/HttpServerRoutes.java#L267
however you are right you cannot access them, we can add this clarification to the javadoc

@akiraly
Copy link
Contributor Author

akiraly commented Oct 30, 2017

That would be great thanks!

Maybe it works like internally that but from user point of view (reading the javadoc) I am more interested in what I can do with it instead of how it is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants