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

Potential bug in `parse_single_header()` #162

Closed
sckott opened this Issue Oct 14, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@sckott

sckott commented Oct 14, 2014

I'm getting an error with parse_single_header() at this line https://github.com/hadley/httr/blob/master/R/perform.R#L77

Here's the call that causes it on my machine:

res <- GET("http://pkp-alm.lib.sfu.ca/api/v5/articles?api_key=<apikey>&ids=10.11606/issn.1981-1624.v18i1p153-165", verbose())
-> GET /api/v5/articles?api_key=<apikey>&ids=10.11606/issn.1981-1624.v18i1p153-165 HTTP/1.1
-> User-Agent: curl/7.30.0 Rcurl/1.95.4.1 httr/0.5.0.9000
-> Host: pkp-alm.lib.sfu.ca
-> Accept-Encoding: gzip
-> Cookie: request_method=GET
-> Accept: application/json, text/xml, application/xml, */*
-> 
<- HTTP/1.1 200 
<- Date: Tue, 14 Oct 2014 16:49:48 GMT
<- Server: Apache/2.2.15 (Red Hat)
<- X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.19
<- Access-Control-Allow-Origin: *
<- Access-Control-Allow-Methods: POST, GET, OPTIONS
<- Access-Control-Max-Age: 1728000
<- X-UA-Compatible: IE=Edge,chrome=1
<- ETag: "46e00759ce8ff06a39a4cf44d82d2b35"
<- Cache-Control: must-revalidate, private, max-age=0
<- X-Request-Id: dc02d47566eb504ce3dff78157be10b7
<- X-Runtime: 0.051983
<- X-Rack-Cache: miss
<- Status: 200
<- Content-Length: 5430
<- Connection: close
<- Content-Type: application/json; charset=utf-8
<- 
Error in names(status) <- c("version", "status", "message") : 
  'names' attribute [3] must be the same length as the vector [2]

This call works fine with curl on the cli, or RCurl. I'm guessing that I'm doing something stupid here.

@sckott

This comment has been minimized.

sckott commented Oct 16, 2014

As you can see on the first line below the response header seems to be missing the message (.e.g, OK)

 [1] "HTTP/1.1 200 "
 [2] "Date: Thu, 16 Oct 2014 21:42:23 GMT"                        
 [3] "Server: Apache/2.2.15 (Red Hat)"                            
 [4] "X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.19"
 [5] "Access-Control-Allow-Origin: *"                             
 [6] "Access-Control-Allow-Methods: POST, GET, OPTIONS"           
 [7] "Access-Control-Max-Age: 1728000"                            
 [8] "X-UA-Compatible: IE=Edge,chrome=1"                          
 [9] "ETag: \"2f82a95e735bf0195787bc4fe667e2be\""                 
[10] "Cache-Control: must-revalidate, private, max-age=0"         
[11] "X-Request-Id: 792e6a896ecca00bc1ce70ff9db16d6e"             
[12] "X-Runtime: 0.052971"                                        
[13] "X-Rack-Cache: miss"                                         
[14] "Status: 200"                                                
[15] "Content-Length: 5706"                                       
[16] "Connection: close"                                          
[17] "Content-Type: application/json; charset=utf-8"              
[18] ""      

So on line https://github.com/hadley/httr/blob/master/R/perform.R#L76 the vector split out returns list of length 2

as.list(strsplit(lines[1], "\\s+")[[1]])
[[1]]
[1] "HTTP/1.1"

[[2]]
[1] "200"

instead of length 3. And then the names assignment https://github.com/hadley/httr/blob/master/R/perform.R#L77 fails.

I don't know you think this is simply a problem for the API provider to fix, or if you thin you could handle this case in httr

@mfenner

This comment has been minimized.

mfenner commented Oct 16, 2014

@hadley hadley closed this in 4f16534 Oct 17, 2014

@sckott

This comment has been minimized.

sckott commented Oct 17, 2014

thanks @hadley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment