apple / apple/swift-openapi-generator

Debugging HTTPBody

Open
#749 4 comments 0 reactions 0 assignees View on GitHub
kind/support status/triage
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

Description

### Question

I'm trying to do what I do in most of my apps: add a button that, when tapped, copies request url, request headers, request body, response headers, response body, etc to the clipboard so that it can be shared with developers for further debugging. This is used when a user has issues with failing url requests on a device the developer might not have access to.

Typically I use https://github.com/pmusolino/Wormholy or https://github.com/kean/Pulse for this as they take care of all this for me. But when used with `swift-openapi-urlsession`, results are mixed: while the requests are listed, and contain most information such as headers and parameters, the tools have troubles picking up request data, and sometimes even response data. Taking a look at the code of `swift-openapi-urlsession`, I assume this is because `swift-openapi-urlsession` does fancy bi-directional stream sending and receiving instead of the basic way that is more commonly used?

So I set myself a breakpoint at func bidirectionalStreamingRequest to `po requestBody` - but this doesn't provide any useful debug representation. I then thought of using `po String(collecting: requestBody!, upTo: 1024)` but that fails too because `collecting` is an async function, so doesn't play well with lldb (or at least I can't figure out how to quickly do so).

Could something be done to make it easier to debug HTTPBody - for example a non async function that spits out the HTTPBody to be used for debugging only?

Would a PR for `swift-openapi-urlsession` that optionally just uses the basic non streaming versions of sending/receiving data be a welcome addition, so that tools such as wormholy or pulse would work? I'm not sure how feasible it is to add bi-directional streaming support to wormholy or pulse... Or is the issue somewhere else and do I have it all wrong? :)

Contributor guide

Open the contributing guide

Research direction

Start at the `bidirectionalStreamingRequest` entry point in `swift-openapi-urlsession` and inspect how `requestBody` is exposed while streaming. Compare the debugging needs described for Wormholy and Pulse with the current request and response behavior; done means the issue has a concrete, agreed approach for making HTTP bodies inspectable or supporting a non-streaming option.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.