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

Expose RAW Response object #25

Open
jlvasquezcollado opened this issue May 22, 2020 · 5 comments
Open

Expose RAW Response object #25

jlvasquezcollado opened this issue May 22, 2020 · 5 comments

Comments

@jlvasquezcollado
Copy link

jlvasquezcollado commented May 22, 2020

NOTE: not really an issue

i want to preform the following using httpie

const file = fs.createWriteStream("file.jpg");
const request = http.get("https://somedomain.com/sampleimage.jpg", function(response) {
  response.pipe(file);
});

whats the best way of doing so?

double note: im asking here as it might be a good example to have for other users

@jlvasquezcollado jlvasquezcollado changed the title Use of HTTPIE for filedownloads? Use of HTTPIE for file downloads? May 22, 2020
@lukeed
Copy link
Owner

lukeed commented May 22, 2020

Hey,

There's no access to the underlying response instance before its completion. I've thought about adding a httpie/raw or raw export to all modes that gives direct access to the response object (thus requiring you to do handle/parse/etc it). This might look something like this:

import { raw } from 'httpie';

async function download(file, writer) {
  const resp = await raw('GET', file, ...);
  return new Promise((res, rej) => {
    resp.on('end', res).on('error', rej);
    writer.pipe(resp);
  });
}

The problem though is that I 100% cannot provide/guarantee any kind of uniformity. Unlike the current httpie@next exports, you would have to use raw specifically knowing if you're using the Fetch, XHR, or Node.js variant.

Put differently, the above snippet would (and could) only work in Node.js.
Where, any import { send } from 'httpie' statement will work regardless of the environment that httpie is running within

@jlvasquezcollado
Copy link
Author

Ah i see i see.

okay thank you, this is very helpful. I'll use the built in http method as a replacement.

@lukeed
Copy link
Owner

lukeed commented May 22, 2020

No problem. I'll keep this open for any feedback, but I definitely won't consider it a blocker/must-have for the next version release.

@lukeed lukeed reopened this May 22, 2020
@lukeed lukeed changed the title Use of HTTPIE for file downloads? Expose RAW Response object May 22, 2020
@lukeed lukeed mentioned this issue Sep 17, 2020
@TehShrike
Copy link

We ran into a related issue. We're talking to the authorize.net API, and even though its responses include the header content-type: application/json the response body contains a BOM, which is invalid, but authorize.net decided to leave it anyway.

So, we need to transform it or something before httpie does its JSON decoding and returns a rejection that doesn't include the body that would let us hack around it.

@TehShrike
Copy link

Including the raw response in the rejection would let us work around the authorize.net stupidity well enough

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

3 participants