Skip to content

fix(cdp): base64-encode non-UTF8 Network.getResponseBody payloads#1921

Open
gilangjavier wants to merge 2 commits intolightpanda-io:mainfrom
gilangjavier:fix-network-getresponsebody-base64
Open

fix(cdp): base64-encode non-UTF8 Network.getResponseBody payloads#1921
gilangjavier wants to merge 2 commits intolightpanda-io:mainfrom
gilangjavier:fix-network-getresponsebody-base64

Conversation

@gilangjavier
Copy link

@gilangjavier gilangjavier commented Mar 19, 2026

Summary

  • return plain text with base64Encoded=false when the captured response body is valid UTF-8
  • base64-encode non-UTF8 payloads and return them with base64Encoded=true
  • add regression tests covering both UTF-8 and binary response paths

Fixes #1903.

@github-actions
Copy link

github-actions bot commented Mar 19, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@gilangjavier
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@krichprollsch
Copy link
Member

Hello @gilangjavier,
Thanks for the contribution.

I'm wondering if we could do that easier: always return a base64 encoded value, even for utf-8 responses.
We could then directly encode into base64 when we allocate to save the captured response and save an additional allocation on getResponseBody.

If we really want to keep utf-8 value non encoded, I guess we have to change captured_responses to store a struct containing a base64encode bool and the data. We can add the the entry and set base64encode field by analyzing the resp mime type + an .empty data during the header done callaback.

And adapt the the captured response callback to save the data depending base64encode.

@krichprollsch krichprollsch self-requested a review March 20, 2026 18:34
@gilangjavier
Copy link
Author

Thanks for the detailed suggestion. I updated the PR to use the simpler approach: Network.getResponseBody now always returns base64-encoded payloads with base64Encoded=true, including UTF-8 responses.\n\nI also updated the tests accordingly:\n- UTF-8 response now asserts aGVsbG8= with base64Encoded=true\n- binary response test remains covered\n\nPushed commit b5b012b to this branch. Please re-check when you have time.

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

Successfully merging this pull request may close these issues.

[Bug] getResponseBody returns raw bytes without proper base64 encoding for binary content

2 participants