Giter VIP home page Giter VIP logo

Comments (9)

icyleaf avatar icyleaf commented on July 18, 2024

i dont know about this is or not a feature, but for now you can add a patch to your code:

class Halite::Response
  def print_debug
    puts "#{version} #{status_code} #{status_message}"
    headers.each do |k, v|
      puts "#{k}: #{v.join(", ")}"
    end
    puts
    puts self
  end
end

url = "https://httpbin.org/get"
r = Halite.get(url)
r.print_debug

output:

HTTP/1.1 200 OK
Connection: keep-alive
Server: gunicorn/19.8.1
Date: Fri, 22 Jun 2018 03:08:03 GMT
Content-Type: application/json
Content-Length: 200
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Via: 1.1 vegur

{"args":{},"headers":{"Accept":"*/*","Accept-Encoding":"gzip, deflate","Connection":"close","Host":"httpbin.org","User-Agent":"Halite/0.3.2"},"origin":"60.206.194.34","url":"https://httpbin.org/get"}

from halite.

icyleaf avatar icyleaf commented on July 18, 2024

Or write your custom logger and enable in each request.

from halite.

 avatar commented on July 18, 2024

Wow, you are very fast providing this, thank you πŸ‘

Firstly, the output seems as expected, but this way its morely a cosmetic output to see this like raw.

This is because of your puts - this inserts self-generated newlines after the header key-value-pairs and between headers and body and helps viewing it, but what i exactly mean is the response buffer (chunks chained) directly to String; it should be the real raw response, like

HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nServer: gunicorn/19.8.1\r\n...

because sometimes itΒ΄s very needed to know whats exactly comes in (or back) :-)

The custom logger would do the same as it did not catch the original response?

Thank you very much - itΒ΄s already a very good starting point :-)

from halite.

icyleaf avatar icyleaf commented on July 18, 2024

Let's improve the code πŸ˜„

class Halite::Response
  def dump
    String.build do |io|
      io << version << " " << status_code << " " << status_message << "\n"
      headers.each do |k, v|
        io << k << ": " << v.join(", ") << "\n"
      end

      io << "\n"
      io << to_s
    end.to_s
  end
end

url = "https://httpbin.org/get"
r = Halite.get(url)
puts r.dump

Is it you want?

from halite.

 avatar commented on July 18, 2024

I do not dare to answer :)

...no... because itΒ΄s adding manually \n again, and i think version, status_code and so on are already always parsed Strings.

But i did not dive deep enough into your source; maybe possible that getting this is not possible if Crystals stdlib always returns already parsed strings. Maybe you got always Strings from their methods and this is the rawest of raw :)

If the last one is correct, than you have already saved me a lot of time because i can reduce doing things in the browser to a minimum - thats really awesome πŸ‘ πŸ’―

from halite.

icyleaf avatar icyleaf commented on July 18, 2024

You are right. all crystal give api is wrapped and it will auto Compression and encoding, check it: https://crystal-lang.org/api/0.25.0/HTTP/Client.html

from halite.

icyleaf avatar icyleaf commented on July 18, 2024

BTW, Crystal also give a method to returns raw by splice but Halite not delegate it: https://github.com/crystal-lang/crystal/blob/master/src/http/client/response.cr#L63

from halite.

 avatar commented on July 18, 2024

Wow - thanks!

Ok, so - i am already very happy with your help and Halite - both were awesome for saving time πŸ₯‡

What do you think about merging above to your master? I think, print_debug or dump are always nice to have πŸ‘

Let's go with Halite :)

from halite.

icyleaf avatar icyleaf commented on July 18, 2024

Done, use to_raw to dump it.

from halite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.