Skip to content

Added an URLRequest extension to generate cURL commands#222

Draft
pstued wants to merge 2 commits into
developfrom
feature/86-copy-as-curl
Draft

Added an URLRequest extension to generate cURL commands#222
pstued wants to merge 2 commits into
developfrom
feature/86-copy-as-curl

Conversation

@pstued

@pstued pstued commented Mar 14, 2021

Copy link
Copy Markdown
Member

This PR adds an extension for URLRequest to transform a request to a cURL command. So far the cURL extension is not hooked up to any UI component since I'm not sure where this would fit the best. I'm open for any input on this one!

What do you think adding a copy as cURL functionality on this screen? Maybe even just as an UIActivity to the UIActivityViewController.
Screenshot 2021-03-14 at 14 04 55

pstued added 2 commits March 14, 2021 12:13
to generate a CURL command including http method, http headers and the http body
if let httpBody = httpBody,
let httpBodyString = String(data: httpBody, encoding: .utf8),
!httpBodyString.isEmpty {
options.append("-d \"\(httpBodyString)\"")

@pstued pstued Mar 14, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently interferes with the header Content-Length and needs further investigation. Maybe Content-Length should be skipped when data are being transmitted.

Example taken from example application:
curl -X POST -H "Content-Length: 30" -d "This is just a simple payload" https://httpbin.org/post

When omitting the Content-Length header request runs smoothly
curl -X POST -d "This is just a simple payload" https://httpbin.org/post

expect(hasCurlAsPrefix) == true
}

it("returns a curl command matching the request URL") {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: false description

@pstued

pstued commented Mar 14, 2021

Copy link
Copy Markdown
Member Author

This is how it could look like. (fyi: @brototyp @lukaswuerzburger)
Screenshot 2021-03-14 at 15 17 51

Will add an image from the system provided ones: https://developer.apple.com/design/resources/

Screenshot 2021-03-14 at 15 23 42

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.

1 participant