0

I'm working with the UnderArmour API and requesting the gpx files for routes of a given location, and it's working fine. However, the download takes a while, and I'd like to download a compressed file per their compression page:

All endpoints support response compression. To enable compression, your request must provide an “Accept-Encoding” with the value set to gzip.

GET /7.1/... HTTP/1.1

Host: api.underarmour.com

Accept: application/json

Accept-Encoding: gzip

The code that I'm using to try this is here (I've replaced my user token with XXX for privacy):

gpxurl <- "https://api.ua.com/v7.1/route/?close_to_location=51.5%2C-0.1&format=gpx&field_set=detailed&limit=40"

r <- GET(gpxurl, add_headers("authorization"=XXX, 
                         "Accept"="application/json",
                         "Accept-Encoding"="gzip"))

The file I'm getting doesn't seem to be compressed. It takes just as long to download as the original file, and I don't have to do any extraction. I can't seem to check the headers that httpbin received because the file returned is in raw form and str(content(r)$headers) fails because the format is simply an atomic vector of bytes sent back from the server. The headers that it sent back are below, which don't include the "Accept" or "Accept-Encoding" headers that I'd expect to be there if it worked correctly.

str(headers(r))

List of 11
 $ content-type               : chr "application/gpx+xml; charset=UTF-8"
 $ content-length             : chr "3506843"
 $ connection                 : chr "keep-alive"
 $ access-control-allow-origin: chr "*"
 $ date                       : chr "Wed, 28 Feb 2018 17:29:37 GMT"
 $ p3p                        : chr "CP=\"NOI DSP COR CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT\""
 $ server                     : chr "edge-proxy/1.0"
 $ uacf-request-id            : chr "9c573cc7-3589-4987-a297-303722b6e6e9"
 $ x-cache                    : chr "Miss from cloudfront"
 $ via                        : chr "1.1 7db492e48a5d55351dcb787a8a14e113.cloudfront.net (CloudFront)"
 $ x-amz-cf-id                : chr "c7zlkuaUXoYVIsmpZvQlHHpGDNobFJw49nzhlg0_gXuGcbWBS6_zCQ=="
 - attr(*, "class")= chr [1:2] "insensitive" "list"

How can I obtain a compressed GPX file from the UnderArmour API?

Community
  • 1
  • 1
Dubukay
  • 1,764
  • 1
  • 8
  • 13
  • `headers(r)` is extracting the headers of the response, not your request. If you do `r <- GET("https://httpbin.org/get", add_headers("Accept-Encoding"="gzip")); content(r)$headers` to see what's in the response, you'll see that the Accept-Encoding header is being passed along as requested. If you not getting the proper response, you should contact support for the API. This doesn't seem to be an R issue. – MrFlick Feb 28 '18 at 19:53
  • @MrFlick I don’t get any useful information from content(r)$headers because the response is sent as raw information, including the headers. content(r)$headers returns an error because the content is in the form of an atomic vector, not a named list. – Dubukay Feb 28 '18 at 20:29
  • That was only for the httpbin endpoint, just to show you the header is being sent with the GET. If the API is not sending you a compressed file, then there's not much you can do from R about that if you are doing what they ask for. – MrFlick Feb 28 '18 at 20:31
  • @MrFlick Gotcha. Is there any way to check that I actually am sending the correct headers given that they’re in “raw”? – Dubukay Feb 28 '18 at 20:37
  • 1
    There are no request headers in the response. That's not how HTTP works. That's just how httpbin works. If the headers are being sent to httpbin, there's no reason to believe they are not being sent to api.ua.com. – MrFlick Feb 28 '18 at 20:39

0 Answers0