Re: How do I deflate content()?

kidstypike <kidstypike.avzfwo-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]> Sun, 25 Dec 2022 09:39:27 +0000
Newsgroups gmane.music.equipment.slimdevices.devel
Organization Logitech Squeezebox Forums
Message-ID <[email protected]>
ser wrote: 
> Here's a full request, with debug enabled:
> 
> > 
Code:
--------------------
  >   > 
  > [22-12-25 02:32:05.2112] Plugins::Assistant::HASS::getEntity (102) Get Entity: http://XX.XX.XX.XX/api/states
  > [22-12-25 02:32:05.2119] Slim::Networking::SimpleHTTP::Base::_createHTTPRequest (96) GETing http://XX.XX.XX.XX/api/states
  > [22-12-25 02:32:05.2136] Slim::Networking::Async::connect (108) Connecting to XX.XX.XX.XX
  > [22-12-25 02:32:05.2156] Slim::Networking::Async::_async_connect (196) Slim::Networking::Async::Socket::HTTP=GLOB(0x56142f8e82a0) => 43 connected, ready to write request
  > [22-12-25 02:32:05.2165] Slim::Networking::Async::write_async (226) Sending: [GET /api/states HTTP/1.0
  > Connection: close
  > Cache-Control: no-cache
  > Accept: */*
  > Accept-Encoding: deflate, gzip
  > Accept-Language: en
  > Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  > Host: XX.XX.XX.XX
  > User-Agent: iTunes/4.7.1 (Linux; N; Debian; x86_64-linux; EN; utf8) SqueezeCenter, Squeezebox Server, Logitech Media Server/8.3.0/1667251155
  > Content-Type: application/json
  > Charset: UTF-8
  > Icy-Metadata: 1
  > 
  > ]
  > [22-12-25 02:32:05.2346] Slim::Networking::Async::HTTP::_http_read (430) Headers read. code: 200 status: OK
  > [22-12-25 02:32:05.2357] Slim::Networking::Async::HTTP::_http_read (431) bless({
  > "::std_case" => { "set-cookie" => "Set-Cookie", "set-cookie2" => "Set-Cookie2" },
  > "content-encoding" => "deflate",
  > "content-length" => 20_736,
  > "content-type" => "application/json",
  > date => "Sun, 25 Dec 2022 08:32:05 GMT",
  > server => "Python/3.10 aiohttp/3.8.1",
  > }, "HTTP::Headers")
  > [22-12-25 02:32:05.2367] Slim::Networking::Async::HTTP::_http_read_body (530) Read body: [851] bytes
  > [22-12-25 02:32:05.2375] Slim::Networking::Async::HTTP::_http_read_body (530) Read body: [16384] bytes
  > [22-12-25 02:32:05.2380] Slim::Networking::Async::HTTP::_http_read_body (530) Read body: [3501] bytes
  > [22-12-25 02:32:05.2383] Slim::Networking::Async::disconnect (251) Close Slim::Networking::Async::Socket::HTTP=GLOB(0x56142f8e82a0) => 43
  > [22-12-25 02:32:05.2387] Slim::Networking::Async::HTTP::_http_read_body (596) closing mode
  > [22-12-25 02:32:05.2389] Slim::Networking::Async::HTTP::_http_read_body (604) Body read
  > [22-12-25 02:32:05.2391] Slim::Networking::SimpleAsyncHTTP::onBody (133) status for http://XX.XX.XX.XX/api/states is 200 OK
  > [22-12-25 02:32:05.2397] Slim::Networking::SimpleAsyncHTTP::onBody (154) Done
  > [22-12-25 02:32:05.2426] Slim::Networking::IO::Select::__ANON__ (130) Error: Select task failed calling Slim::Networking::Async::HTTP::_http_read_body: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "\x{fffd}\x{fffd}/\x{fffd}...") at /var/lib/squeezeboxserver/cache/InstalledPlugins/Plugins/Assistant/HASS.pm line 111.
  > ; fh=Slim::Networking::Async::Socket::HTTP=GLOB(0x56142f8e82a0)
  > 
--------------------
> > 
> 
> As expected, the library is accepting deflate, and the Home Assistant
> server is delivering deflate.
> 
> I couldn't figure out how to check the status of
> Slim::Networking::SimpleHTTP::hasZlib. As I mentioned, zlib1g is in
> the dependencies for the package:
> 
> > 
Code:
--------------------
  >   > 
  > ...
  > Package: logitechmediaserver
  > Version: 8.3.0
  > State: installed
  > ...
  > Depends: perl (>= 5.10.0), adduser, libc6, libgcc1, libstdc++6, zlib1g,
  > libio-socket-ssl-perl, ca-certificates, libcrypt-openssl-rsa-perl
  > 
--------------------
> > 
> 
> I tried dumping the structure out with $log a couple of ways; how
> would I inspect this? I did find the code in SimpleHTTP/Base.pm that
> only adds the header for accepting compressed data IFF zlib is
> available, so there's a secondary indication that it's there.
> $response->content is certainly not deflating the data, though; is
> there a way I can do it manually? I'm getting content, and it's still
> compressed by the time the plugin gets it -- is there a simple
> function to uncompress it?
> 
> *Edit:* After some trial and error, I figured out that I needed to
> import SimpleHTTP::Base and access hasZlib there
> (Slim::Networking::SimpleHTTP::Base->hasZlib). It returns '1', so it's
> available:
> 
> code:
> > 
Code:
--------------------
  >   > $log->info('hasZlib: '.Slim::Networking::SimpleHTTP::Base->hasZlib);
--------------------
> > 
> output:
> > 
Code:
--------------------
  >   > [22-12-25 03:11:30.1401] Plugins::Assistant::HASS::__ANON__ (112) hasZlib: 1
--------------------
> > 
> 
> So I tried using unzip in that same package to deflate the payload:
> 
> > 
Code:
--------------------
  >   > $result = decode_json(Slim::Networking::SimpleHTTP::Base->unzip($response->content));
--------------------
> > 
> 
> and now it's complaining about something else:
> 
> > 
Code:
--------------------
  >   > 
  > [22-12-25 03:11:30.1429] Slim::Networking::IO::Select::__ANON__ (130) Error: Select task failed calling Slim::Networking::Async::HTTP::_http_read_body: Can't locate object method "header" via package "Slim::Networking::SimpleHTTP::Base" at /usr/share/perl5/Slim/Networking/SimpleHTTP/Base.pm line 311.
  > 
--------------------
> > 
> 
> so I think I'm on the wrong track with that.
> 
> Honestly... can I disable accepting compressed payloads in the plugin?

Michael won't see your edits. but he'll see my post that contains your
edits.



*Server - LMS 8.3.0 *RPi4B 4GB/NanoSound ONE case/pCP 8.1.0 - 75K
library, playlists & LMS cache on Sata SSD (ntfs)

*Lounge* - DAC32 - AudioEngine B2
*Office* - RPi 3B+/HiFiBerry DAC HAT/RPi screen - Edifier D12
*Bedroom* - Echo Show 8

*Spares* - 1xSB Touch, 1xSB3, 4xRPi, AVI DM5 speakers
------------------------------------------------------------------------
kidstypike's Profile: http://forums.slimdevices.com/member.php?userid=10436
View this thread: http://forums.slimdevices.com/showthread.php?t=117244