spoa-mirror icon indicating copy to clipboard operation
spoa-mirror copied to clipboard

Is it possible to capture the HTTP reposone content

Open wwyhy opened this issue 2 years ago • 6 comments

Hi,

the traffic is mirrored and send to mirror-url by spoa agent. is it possible to capture the HTTP reposone content (mirrior-url returned to spoa-agent)?

thanks!

wwyhy avatar May 12 '23 02:05 wwyhy

Hello @wwyhy,

if you start the spoa-mirror program using the '-l' option, then you can see the responses of the mirror server in the log file, for example:

[ 0][    0.000489] --- start --- 2023-05-12 15:41:02 -------------------------
[ 1][    3.617709] "GET http://localhost:8100/ HTTP/1.1" 200 0/44 0.428 ok
[ 2][   13.861889] "GET http://localhost:8100/ HTTP/???" 0 0/0 0.496 Failed to connect to localhost port 8100: Connection refused
[ 0][   28.025583] --- stop  --- 2023-05-12 15:41:30 -------------------------

As far as the response content is concerned, it is ignored.

If the program is compiled in debug mode (using --enable-debug when starting the configure script), then in that log you can find a more detailed display of the response from the mirror server.

..
[ 1][    7.905593]   mir_curl_ev_socket_cb(0x7f9a44000b60, 0x7f9a44022fe8, 0x00000001) {
[ 1][    7.905601]     mir_curl_debug_cb(0x7f9a4401b8f0, 0, 0x7f9a49c73040, 39, (nil)) {
[ 1][    7.905602]       cURL: [0x7f9a4401b8f0]: 0 <Mark bundle as not supporting multiuse.>
[ 1][    7.905603]     } = 0
[ 1][    7.905605]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 17, (nil)) {
[ 1][    7.905617]       cURL: [0x7f9a4401b8f0]: 1 <HTTP/1.1 200 OK..>
[ 1][    7.905618]     } = 0
[ 1][    7.905619]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 31, (nil)) {
[ 1][    7.905620]       cURL: [0x7f9a4401b8f0]: 1 <Server: thttpd/2.29 23May2018..>
[ 1][    7.905621]     } = 0
[ 1][    7.905622]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 40, (nil)) {
[ 1][    7.905623]       cURL: [0x7f9a4401b8f0]: 1 <Content-Type: text/html; charset=UTF-8..>
[ 1][    7.905624]     } = 0
[ 1][    7.905624]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 37, (nil)) {
[ 1][    7.905625]       cURL: [0x7f9a4401b8f0]: 1 <Date: Fri, 12 May 2023 13:46:44 GMT..>
[ 1][    7.905626]     } = 0
[ 1][    7.905627]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 46, (nil)) {
[ 1][    7.905628]       cURL: [0x7f9a4401b8f0]: 1 <Last-Modified: Thu, 11 May 2023 02:15:16 GMT..>
[ 1][    7.905628]     } = 0
[ 1][    7.905629]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 22, (nil)) {
[ 1][    7.905630]       cURL: [0x7f9a4401b8f0]: 1 <Accept-Ranges: bytes..>
[ 1][    7.905630]     } = 0
[ 1][    7.905631]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 19, (nil)) {
[ 1][    7.905632]       cURL: [0x7f9a4401b8f0]: 1 <Connection: close..>
[ 1][    7.905633]     } = 0
[ 1][    7.905634]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a44023030, 20, (nil)) {
[ 1][    7.905634]       cURL: [0x7f9a4401b8f0]: 1 <Content-Length: 44..>
[ 1][    7.905635]     } = 0
[ 1][    7.905636]     mir_curl_debug_cb(0x7f9a4401b8f0, 1, 0x7f9a4401d888, 2, (nil)) {
[ 1][    7.905637]       cURL: [0x7f9a4401b8f0]: 1 <..>
[ 1][    7.905637]     } = 0
[ 1][    7.905638]     mir_curl_debug_cb(0x7f9a4401b8f0, 3, 0x7f9a4401d88a, 44, (nil)) {
[ 1][    7.905639]       cURL: [0x7f9a4401b8f0]: 3 <<html><body><p>Did I err?</p></body></html>.>
[ 1][    7.905640]     } = 0
..

zaga00 avatar May 12 '23 13:05 zaga00

@zaga00

Thanks for you reply.

====> As far as the response content is concerned, it is ignored. We are compliled it with "--enable-debug" parameter, and run it with "--logfile w:/var/log/haproxy/mirror.log". Now we have a requirement to compare the response content (POST method) between PROD env and STAGE env, so is there any way to store the resonse content to log file or somewhere? or do we have to change the source code?

Thanks! Br, wwyhy

wwyhy avatar May 15 '23 02:05 wwyhy

Hello,

to make this work, code must be added to the mir_curl_write_cb() function (which for the time being ignores all the content it receives from the mirror server).

zaga00 avatar May 15 '23 08:05 zaga00

@zaga00 Thanks!

One more issue here, we tested and found that it is working for text with POST method. But it is doesn't work for audio(streaming) with POST method. any suggestion?

Br, wwyhy

wwyhy avatar May 22 '23 09:05 wwyhy

Hello,

I think that it is not suitable for streaming because spoa-mirror can send a request to the mirror url in just one step. Partial progress can be achieved by using the http-buffer-request option in the haproxy configuration, but the body of the http request must still be in one piece.

zaga00 avatar May 22 '23 16:05 zaga00

The option is already enabled.

I increased the max-frame-size of agent, it works now. not sure if will meet new issue. :)

wwyhy avatar May 23 '23 02:05 wwyhy