Comments (9)
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.
Or write your custom logger and enable in each request.
from halite.
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.
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.
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.
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.
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.
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.
Done, use to_raw
to dump it.
from halite.
Related Issues (20)
- Two memory leaks HOT 6
- JSON post issue HOT 1
- Get amount of data dowloaded, info ...
- Add note saying that copying byte by byte is slow HOT 1
- Change tls to Bool or OpenSSL::SSL::Context::Client HOT 1
- Feature: HTTP Proxy HOT 3
- 0.9.0 was released with 0.8.0 version HOT 2
- Add endpoint as configuration option HOT 5
- request option values repeated when reusing clients HOT 6
- Bug: can not use logging with bool
- Client request option incorrect when used as class variable HOT 4
- Basic Auth creates bad headers in crystal 0.29.0 HOT 2
- Support persistant connections HOT 2
- Compatibility with Crystal 0.34 HOT 2
- Is Halite Fiber-safe? HOT 7
- Unhandled exception: HTTP::Client::Response#body_io cannot be nil (NilAssertionError) HOT 1
- Endpoint joining is broken HOT 4
- APIError#status_message doesn't actually exist HOT 3
- since 0.10.7 halite breaks my gitlab endpoint HOT 1
- Bug when using `timeout()` inside `Halite::Client.new do`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from halite.