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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to resolve variables with file data #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nishnet2002
Copy link

@nishnet2002 nishnet2002 commented Jan 31, 2017

This PR will resolve variables declared with !file(SomeValidFile) with contents of the file.
The Contents of $fileData will hold String data instead of file pointer.
eg: # $fileData = !file(SomeValidFile)

I wanted to switch between users with multiple cookies. Since, having a big 馃崻, switching between users was painful.
This changes will help to copy data from file, and use it in Headers as well as any other segment.

Input File

# Define Cookies
# $JohnCookie = !file(/tmp/JohnCookie)
# $MyCookie = !file(/tmp/MyCookie)
#
# Set User
# $globalCookie = $MyCookie
POST http://httpbin.org/post
Cookie: $globalCookie
SomeData

# Run 2 Using POST Data 
POST http://httpbin.org/post
Cookie: $globalCookie
$globalCookie

Output

{
  "args": {},
  "data": "MyCookie",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "8",
    "Cookie": "MyCookie",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.13.0"
  },
  "json": null,
  "origin": "XXX",
  "url": "http://httpbin.org/post"
}

// status code: 200
// Server: nginx
// Date: Tue, 31 Jan 2017 18:48:41 GMT
// Content-Type: application/json
// Content-Length: 365
// Connection: keep-alive
// Access-Control-Allow-Origin: *
// Access-Control-Allow-Credentials: true

Error Handling

when file is incorrect or missing:

Prints at bottom on vi

 File: /MyCookie not found

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

Successfully merging this pull request may close these issues.

None yet

1 participant