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

[SR-8759] httpBody is not sent by URLSessionDataTask to the server that URLSession has received cookie #3636

Closed
norio-nomura opened this issue Sep 15, 2018 · 4 comments

Comments

@norio-nomura
Copy link
Contributor

Previous ID SR-8759
Radar None
Original Reporter @norio-nomura
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

swift-4.2-DEVELOPMENT-SNAPSHOT-2018-09-07-a or later on Linux

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: aa18d826eb92d2c55d1554ebd6caceb4

Issue Description:

Reproducing steps

  1. docker run -it --rm norionomura/swift:4220180907a

  2. curl -s https://gist.githubusercontent.com/norio-nomura/73c3a12db6a9d615e239954259ff89cf/raw/00b4351496c153e13af0a2674bb8fe75e661a70f/httpBodyIsNotSentToTheDomainThatReceivedCookie.swift|swift -

log:

$ docker run -it --rm norionomura/swift:4220180907a
root@a6b6631911aa:/# curl -s https://gist.githubusercontent.com/norio-nomura/73c3a12db6a9d615e239954259ff89cf/raw/00b4351496c153e13af0a2674bb8fe75e661a70f/httpBodyIsNotSentToTheDomainThatReceivedCookie.swift|swift -
request.httpBody: Optional(15 bytes)
postTask.originalRequest.httpBody: nil
-- response body begin
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "deflate, gzip", 
    "Accept-Language": "en", 
    "Connection": "close", 
    "Content-Length": "0", 
    "Content-Type": "application/json", 
    "Cookie": "freeform=test", 
    "Host": "httpbin.org", 
    "User-Agent": "swift (unknown version) curl/7.47.0"
  }, 
  "json": null, 
  "origin": "180.196.246.165", 
  "url": "http://httpbin.org/post"
}

-- response body end

postTask.originalRequest.httpBody: nil indicates httpBody is lost.
Response body indicates {{httpBody is not received on http://httpbin.org/post.

Until swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-25-a, it works as expected.

$ docker run -it --rm norionomura/swift:4220180825a
root@452e49dbf55d:/# curl -s https://gist.githubusercontent.com/norio-nomura/73c3a12db6a9d615e239954259ff89cf/raw/00b4351496c153e13af0a2674bb8fe75e661a70f/httpBodyIsNotSentToTheDomainThatReceivedCookie.swift|swift -
request.httpBody: Optional(15 bytes)
postTask.originalRequest.httpBody: Optional(15 bytes)
-- response body begin
{
  "args": {}, 
  "data": "{\"key\":\"value\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "deflate, gzip", 
    "Accept-Language": "en", 
    "Connection": "close", 
    "Content-Length": "15", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "swift (unknown version) curl/7.47.0"
  }, 
  "json": {
    "key": "value"
  }, 
  "origin": "180.196.246.165", 
  "url": "http://httpbin.org/post"
}

-- response body end

postTask.originalRequest.httpBody: Optional(15 bytes) indicates that httpBody is passed to URLSessionDataTask.
It succeeded to post httpBody to http://httpbin.org/post.

swift-4.2-branch branch is affected by this issue.
master branch is not affected by this issue.

@norio-nomura
Copy link
Contributor Author

Workaround: Use URLSession configured with httpCookieAcceptPolicy = .never

  let session: URLSession = {
    let configuration = URLSessionConfiguration.default
    configuration.httpCookieAcceptPolicy = .never
    return URLSession(
      configuration: configuration,
      delegate: nil,
      delegateQueue: OperationQueue()
    )
  }()

@norio-nomura
Copy link
Contributor Author

This issue should be resolved by cherry-picking 9019439

@norio-nomura
Copy link
Contributor Author

opened #1698

@norio-nomura
Copy link
Contributor Author

confirmed that this issue has been resolved on swift-4.2-DEVELOPMENT-SNAPSHOT-2018-09-21-a

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant