forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 🧰 Changes - support `timeout` paramater - remove `final newline` - remove `FoundationNetworking` - remove extra code in `multipart/form-data` ## 🧬 QA & Testing I fixed test code in `/httpsnippet/src/targets/swift/urlsession/fixtures/` `npm run test`
- Loading branch information
1 parent
fd0dd80
commit e3a78da
Showing
24 changed files
with
120 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
src/targets/swift/urlsession/fixtures/application-form-encoded.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let headers = ["content-type": "application/x-www-form-urlencoded"] | ||
|
||
var postData = Data("foo=bar".utf8) | ||
postData.append(Data("&hello=world".utf8)) | ||
let parameters = [ | ||
"foo": "bar", | ||
"hello": "world", | ||
] | ||
let joinedParameters = parameters.map { "\($0.key)=\($0.value)" }.joined(separator: "&") | ||
let postData = Data(joinedParameters.utf8) | ||
|
||
let url = URL(string: "https://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.allHTTPHeaderFields = headers | ||
request.timeoutInterval = 10 | ||
request.allHTTPHeaderFields = ["content-type": "application/x-www-form-urlencoded"] | ||
request.httpBody = postData | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let headers = ["cookie": "foo=bar; bar=baz"] | ||
|
||
let url = URL(string: "https://httpbin.org/cookies")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.allHTTPHeaderFields = headers | ||
request.timeoutInterval = 10 | ||
request.allHTTPHeaderFields = ["cookie": "foo=bar; bar=baz"] | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let url = URL(string: "https://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "PROPFIND" | ||
request.timeoutInterval = 10 | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let headers = [ | ||
let url = URL(string: "https://httpbin.org/headers")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.timeoutInterval = 10 | ||
request.allHTTPHeaderFields = [ | ||
"accept": "application/json", | ||
"x-foo": "Bar", | ||
"x-bar": "Foo", | ||
"quoted-value": "\"quoted\" 'string'" | ||
] | ||
|
||
let url = URL(string: "https://httpbin.org/headers")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.allHTTPHeaderFields = headers | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let url = URL(string: "http://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.timeoutInterval = 10 | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let url = URL(string: "https://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "GET" | ||
request.timeoutInterval = 10 | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let headers = ["content-type": "application/json"] | ||
let parameters = ["foo": nil] as [String : Any] | ||
|
||
let postData = try JSONSerialization.data(withJSONObject: parameters, options: []) | ||
|
||
let url = URL(string: "https://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.allHTTPHeaderFields = headers | ||
request.timeoutInterval = 10 | ||
request.allHTTPHeaderFields = ["content-type": "application/json"] | ||
request.httpBody = postData | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
9 changes: 3 additions & 6 deletions
9
src/targets/swift/urlsession/fixtures/jsonObj-multiline.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
let headers = ["content-type": "application/json"] | ||
let parameters = ["foo": "bar"] as [String : Any] | ||
|
||
let postData = try JSONSerialization.data(withJSONObject: parameters, options: []) | ||
|
||
let url = URL(string: "https://httpbin.org/anything")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.allHTTPHeaderFields = headers | ||
request.timeoutInterval = 10 | ||
request.allHTTPHeaderFields = ["content-type": "application/json"] | ||
request.httpBody = postData | ||
|
||
let (data, response) = try await URLSession.shared.data(for: request) | ||
print(String(decoding: data, as: UTF8.self)) | ||
print(String(decoding: data, as: UTF8.self)) |
Oops, something went wrong.