qustavo/httplab

Support non text responses

Closed this issue · 9 comments

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.

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)

That should probably work

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

@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.

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.

Implemented here: 157eba5

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 ...)

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

Sure! #18