Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an URLRequest extension to generate cURL commands #222

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

pstued
Copy link
Member

@pstued pstued commented Mar 14, 2021

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)\"")
Copy link
Member Author

@pstued pstued Mar 14, 2021

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
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
Copy link
Member Author

pstued commented Mar 14, 2021

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