Read debug log for HTTP requests using spring webclient

I am using Spring reactive WebClient to send requests to the http server. Inorder, to view the basic request and response sent, I turned on debugging logging for the reactor.ipc.netty package.

Headers for outgoing requests can be viewed normally.

Tho I send and receive plain text via http, the log contains the request and responses in the following format (is it hex?)

I'm not sure how to view the logged data in an easy to understand way. Even better, register your request and response in a clear way.

Below is a snippet of recorded data

  +-------------------------------------------------+ | 0 1 2 3 4 5 6 7 8 9 abcdef | +--------+-------------------------------------------------+----------------+ |00000000| 47 45 54 20 2f 53 65 61 72 63 68 5f 47 43 2e 61 |GET /Search_GC.a| |00000010| 73 70 78 20 48 54 54 50 2f 31 2e 31 0d 0a 75 73 |spx HTTP/1.1..us| |00000020| 65 72 2d 61 67 65 6e 74 3a 20 52 65 61 63 74 6f |er-agent: Reacto| |00000030| 72 4e 65 74 74 79 2f 30 2e 37 2e 32 2e 52 45 4c |rNetty/0.7.2.REL| |00000040| 45 41 53 45 0d 0a 68 6f 73 74 3a 20 63 65 6f 6b |EASE..host: ceok| |00000050| 61 72 6e 61 74 61 6b 61 2e 6b 61 72 2e 6e 69 63 |arnataka.kar.nic| |00000060| 2e 69 6e 0d 0a 61 63 63 65 70 74 3a 20 2a 2f 2a |.in..accept: */*| |00000070| 0d 0a 61 63 63 65 70 74 2d 65 6e 63 6f 64 69 6e |..accept-encodin| |00000080| 67 3a 20 67 7a 69 70 0d 0a 63 6f 6e 74 65 6e 74 |g: gzip..content| |00000090| 2d 6c 65 6e 67 74 68 3a 20 30 0d 0a 0d 0a |-length: 0.... | +--------+-------------------------------------------------+----------------+ 

Found an unanswered question that should happen due to the same library: Reading an HttpContent that has PooledUnsafeDirectByteBuf

Raised the question here

There seems to be an orthodox view that debugging is not required for reactive clients. These are completely pointless arguments, because we use tools like rest client , postman , curl , httpie and others to send a request and view the response

+2
spring webclient project-reactor spring-webflux reactor-netty
source share
2 answers

It seems that the responding server is returning gzipped content, so it makes sense that you cannot read it.

If you really want to grab the raw HTTP layer, make sure the request header does not indicate that it can accept GZipped content ( accept-encoding: gzip ).

Another alternative could be registering the request at a different level, when it has already been unpacked from the raw data stream but not yet processed by your application code - I'm not sure how this works in the Reactive webclient, though;)

-one
source

This is a very subjective question.

You may not find this format readable / useful, but I think this is the opposite for several reasons. Hexadecimal is really useful here, as HTTP can be tricky:

  • It is not always easy to read special characters in magazines (character encoding, etc.).
  • servers / clients can interpret / analyze headers in many ways.
  • it’s really hard to keep track of problems when HTTP control characters are enabled without it

All this boils down to really transmit what is sent / received over the network, which is usually visible if you are looking at a specific problem.

But I agree that this level of detail should not be the first and only available debugging information. There should be an intermediate level at which you can get the basics about HTTP exchange without looking at the raw hexadecimal data.

For more on this, please follow the dedicated issue in Reactor Netty .

-one
source

All Articles