Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OHHTTPStubs — CHANGELOG

## Master

* Fixed `URLRequest.ohhttpStubs_httpBody` function in Swift 3 and 4.
[@mplorentz](https://github.com/mplorentz)
* Added absolute url matcher.
[@victorg1991](https://github.com/victorg1991)
[#254](https://github.com/AliSoftware/OHHTTPStubs/pull/254)
Expand Down
6 changes: 6 additions & 0 deletions OHHTTPStubs/Sources/Swift/OHHTTPStubsSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
return rangeOfString(string) != nil
}
}
#else
extension URLRequest {
public var ohhttpStubs_httpBody: Data? {
return (self as NSURLRequest).ohhttpStubs_HTTPBody()
}
}
#endif


Expand Down
14 changes: 14 additions & 0 deletions OHHTTPStubs/UnitTests/Test Suites/SwiftHelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@ class SwiftHelpersTests : XCTestCase {

XCTAssertFalse(matchesHeader)
}

func test_ohhttpStubs_httpBody() {
#if swift(>=3.0)
let data = "Hello world".data(using: .utf8)
var req = URLRequest(url: URL(string: "foo://bar")!)
req.httpBody = data
XCTAssertEqual(req.ohhttpStubs_httpBody, data)
#else
let data = "Hello world".dataUsingEncoding(NSUTF8StringEncoding)
let req = NSMutableURLRequest(URL: NSURL(string: "foo://bar")!)
req.HTTPBody = data
XCTAssertEqual(req.OHHTTPStubs_HTTPBody(), data)
#endif
}

let sampleURLs = [
// Absolute URLs
Expand Down