-
Notifications
You must be signed in to change notification settings - Fork 322
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
Logging request payload\data\body with httplog is broken in 3.0.0 #437
Comments
The change introduced in #412 is responsible for this behaviour. Previously |
@igorigorigorigor This PR should bring necessary changes to HTTP.rb for me to then be able to send a PR to httplog – #438. |
The solution is not ideal, because you can't simply do |
@tycooon I was actually thinking of that the httplog gem would just do HTTP.post("http://example.com", body: "body")
# [httplog] Data: "body"
HTTP.post("http://example.com", json: { key: "value" })
# [httplog] Data: "{\"key\":\"value\"}"
HTTP.post("https://example.com", body: Enumerator.new { |y| ... })
# [httplog] Data: #<Enumerator: ...>
HTTP.post("https://example.com", body: File.open("/path/to/file"))
# [httplog] Data: #<File:/path/to/file>
HTTP.post("https://example.com", form: {file: HTTP::FormData::File.new("/path/to/file")})
# [httplog] Data: #<HTTP::FormData::Multipart:0x007fedd70d1728 @boundary="---------------------65612a9a946c41388f3563b91ad41f03fb85a9587e", @glue="-----------------------65612a9a946c41388f3563b91ad41f03fb85a9587e\r\n", @tail="-----------------------65612a9a946c41388f3563b91ad41f03fb85a9587e--\r\n", @io=#<HTTP::FormData::CompositeIO:0x007fedd70d1048 @index=0, @buffer="", @ios=[#<StringIO:0x007fedd70d0f80>, #<HTTP::FormData::Multipart::Param:0x007fedd70d1610 @name="file", @part=#<HTTP::FormData::File:0x007fedd70d18b8 @io=#<File:/path/to/file>, @content_type="application/octet-stream", @filename="Gemfile">, @io=#<HTTP::FormData::CompositeIO:0x007fedd70d12a0 @index=0, @buffer="", @ios=[#<StringIO:0x007fedd70d1228>, #<HTTP::FormData::File:0x007fedd70d18b8 @io=#<File:/path/to/file>, @content_type="application/octet-stream", @filename="file">, #<StringIO:0x007fedd70d1200>]>>, #<StringIO:0x007fedd70d0f58>]>> For me this would be how I would like httplog to log my requests; if I'm passing for request body anything other than a string, then the request body will probably be large and I would like to avoid logging it, because it could cause my logs to grow in size. What do you think about that? |
@janko-m this doesn't work well with FormData: > HTTP.build_request(:post, "http://a.com", form: { a: 1 }).body.source.inspect
=> "#<HTTP::FormData::Urlencoded:0x00007fd1d5986530 @io=#<StringIO:0x00007fd1d59860a8>>" |
@tycooon Yeah, URL-encoded request bodies really should be shown as strings, and not as Ruby objects. It seems that you've already solved everything in trusche/httplog#56. Yes, the |
@tycooon Is httplog now working properly? Can this issue be closed? |
Yep, we fixed it here trusche/httplog#56. |
Awesome, thank you! |
Httplog(https://github.com/trusche/httplog) logs kind of memory pointer instead of the payload\data\body itself.
D, [2017-10-17T18:42:06.013390 #53965] DEBUG -- : [httplog] Sending: POST https://address.domain/api_method
D, [2017-10-17T18:42:06.013533 #53965] DEBUG -- : [httplog] Data: #<HTTP::Request::Body:0x007f93735632c8>
Here is my code for this
payload = { :param_1 => param_1.to_s, :param_2 => param_2.to_s, :param_3 => param_3.to_s}.to_json
HTTP.headers("id" => ID, :"User-Agent" => user_agent).post(url), :body => payload)
The text was updated successfully, but these errors were encountered: