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

No HTTP body for requests #16

Closed
jasoncabot opened this issue Nov 25, 2015 · 4 comments
Closed

No HTTP body for requests #16

jasoncabot opened this issue Nov 25, 2015 · 4 comments

Comments

@jasoncabot
Copy link
Contributor

All requests that send data show as "Request body is empty" for the request body despite having the correct Content-Length set in the header

The reason is because when startLoading() is called in NFXProtocol the getNFXBody() is nil

I believe this is the same issue as:

https://github.com/AliSoftware/OHHTTPStubs/wiki/Testing-for-the-request-body-in-your-stubs

I'm currently seeing if there's a different place to trap and save this data

I'm also using Alamofire but I'm not sure it's related to that

@jasoncabot
Copy link
Contributor Author

And I believe there is a radar for the same issue

http://openradar.appspot.com/15993891

@jasoncabot
Copy link
Contributor Author

So one possible solution is to set a property when constructing the request. I'm doing the following in my URLRequestConvertible subclass but the solution shouldn't be specific to Alamofire

if let bodyData = mutableURLRequest.HTTPBody {
    NSURLProtocol.setProperty(bodyData, forKey: "NFXBodyData", inRequest: mutableURLRequest)
}

Then I've modified NFXHelper.getNFXBody() to return:

func getNFXBody() -> NSData
{
    return HTTPBody ?? NSURLProtocol.propertyForKey("NFXBodyData", inRequest: self) as? NSData ?? NSData()
}

And everything now just works :)

@jasoncabot
Copy link
Contributor Author

I've made a pull request for the workaround #18

@kasketis
Copy link
Owner

Merged ;)

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

No branches or pull requests

2 participants