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

Test to demonstrate issue #64 #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Tests/EmbassyTests/HTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,48 @@ class HTTPServerTests: XCTestCase {
let receivedString = String(bytes: receivedInputData.joined(separator: []), encoding: String.Encoding.utf8)
XCTAssertEqual(receivedString, postBodyString)
}

func testPostEmptyBody() {
let port = try! getUnusedTCPPort()

var receivedInputData: [Data] = []
let server = DefaultHTTPServer(eventLoop: loop, port: port) {
(
environ: [String: Any],
startResponse: ((String, [(String, String)]) -> Void),
sendBody: @escaping ((Data) -> Void)
) in
if environ["HTTP_EXPECT"] as? String == "100-continue" {
startResponse("100 Continue", [])
} else {
startResponse("200 OK", [])
}
let input = environ["swsgi.input"] as! SWSGIInput
input { data in
receivedInputData.append(data)
sendBody(data)
}
}

try! server.start()

queue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(1 * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {
var request = URLRequest(url: URL(string: "http://[::1]:\(port)")!)
request.httpMethod = "POST"
let task = self.session.dataTask(with: request, completionHandler: { (data, response, error) in
self.loop.stop()
})
task.resume()
}

loop.runForever()

// ensure EOF is passed
XCTAssertEqual(receivedInputData.last?.count, 0)

let receivedString = String(bytes: receivedInputData.joined(separator: []), encoding: String.Encoding.utf8)
XCTAssertEqual(receivedString, "")
}

func testPostWithInitialBody() {
let port = try! getUnusedTCPPort()
Expand Down