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

Support non text responses #14

Closed
qustavo opened this issue Mar 3, 2017 · 9 comments
Closed

Support non text responses #14

qustavo opened this issue Mar 3, 2017 · 9 comments

Comments

@qustavo
Copy link
Owner

qustavo commented Mar 3, 2017

Only plain text responses are supported now, non text like binaries needs to be supported, this would probably involve changes on the UI as well.

@jacksgt
Copy link

jacksgt commented Mar 3, 2017

The simplest solution would probably be to implement a hotkey/shortcut/mode, which interprets the string specified in the "Body" Window as a path to a file (which then gets sent to the client, instead of the string).

E.g.:

Ctrl+f (or Ctrl+o)

+-Body------------------+
| ~/Documents/test.txt  |
+-----------------------+

-> Sends Content of ~/Documents/test.txt (in binary) to the client. (Headers can still be set manually)

@qustavo
Copy link
Owner Author

qustavo commented Mar 3, 2017

That should probably work

@qustavo
Copy link
Owner Author

qustavo commented Mar 5, 2017

@jacksgt I'm working on this here: https://github.com/gchaincl/httplab/tree/respond-with-file, mind to take a look?

@jacksgt
Copy link

jacksgt commented Mar 5, 2017

@gchaincl Maybe I'm doing something wrong, but it doesn't (yet?) work for me:

$ echo 'this is a test' > /tmp/test.txt
$ curl -i http://localhost:10080
HTTP/1.1 200 OK
X-Server: HTTPLab
Date: Sun, 05 Mar 2017 19:32:00 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

In httplab I selected "Body (File)" (Ctrl-b), set the string to /tmp/test.txt and applied with Ctrl-a.

@qustavo
Copy link
Owner Author

qustavo commented Mar 5, 2017

Sorry I didn't explain how it works, make sure one of your responses in .httplab file contains a "File": "" section like this example:

{
  "Responses": {
    "create": {
      "Status": 201,
      "Delay": 0,
      "Body": "OK",
      "File": "/tmp/test.txt",
      "Headers": {
        "X-Server": "HTTPLab"
      }
    }
  }
}

Then, open httplab, Ctrl+L, load the response and hit Ctrl+b to choose between input or file body.

@qustavo
Copy link
Owner Author

qustavo commented Mar 5, 2017

Implemented here: 157eba5

@qustavo qustavo closed this as completed Mar 5, 2017
@jacksgt
Copy link

jacksgt commented Mar 6, 2017

Awesome, just one more thing:

It would be very nice to also support the home directory with ~.
Currently when I enter ~/test.txt (in the Ctrl-o popup), I get: open ~/test.txt: no such file or directory

Maybe even support for all environment variables is possible? ($TMP, $USER, $PATH, $LANGUAGE ...)

@qustavo
Copy link
Owner Author

qustavo commented Mar 6, 2017

that would be awesome, would you mind to open a new issue?

@jacksgt
Copy link

jacksgt commented Mar 6, 2017

Sure! #18

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