Pino Toscano
2020-May-19 10:19 UTC
[Libguestfs] [v2v PATCH] vCenter: fix parsing of HTTP status string (RHBZ#1837328)
vCenter 7 answers with an HTTP/2 status string, so we cannot extract the status code from it by using fixed positions in that string. Hence, pick the status code by reading what's after the whitespace. Tested with vCenter 6.5 and 7. --- v2v/vCenter.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml index c28a4ced..4c128b0c 100644 --- a/v2v/vCenter.ml +++ b/v2v/vCenter.ml @@ -190,7 +190,9 @@ and fetch_headers_from_url password_file uri sslverify https_url | [] -> dump_response stderr; error (f_"vcenter: no status code in output of ‘curl’ command. Is ‘curl’ installed?") - | ss -> String.sub (List.hd (List.rev ss)) 9 3 in + | ss -> + let s = List.hd (List.rev ss) in + String.sub s (String.index s ' ' + 1) 3 in let headers List.map ( -- 2.25.4
Richard W.M. Jones
2020-May-19 11:24 UTC
Re: [Libguestfs] [v2v PATCH] vCenter: fix parsing of HTTP status string (RHBZ#1837328)
On Tue, May 19, 2020 at 12:19:58PM +0200, Pino Toscano wrote:> vCenter 7 answers with an HTTP/2 status string, so we cannot extract > the status code from it by using fixed positions in that string. > Hence, pick the status code by reading what's after the whitespace. > > Tested with vCenter 6.5 and 7. > --- > v2v/vCenter.ml | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml > index c28a4ced..4c128b0c 100644 > --- a/v2v/vCenter.ml > +++ b/v2v/vCenter.ml > @@ -190,7 +190,9 @@ and fetch_headers_from_url password_file uri sslverify https_url > | [] -> > dump_response stderr; > error (f_"vcenter: no status code in output of ‘curl’ command. Is ‘curl’ installed?") > - | ss -> String.sub (List.hd (List.rev ss)) 9 3 in > + | ss -> > + let s = List.hd (List.rev ss) in > + String.sub s (String.index s ' ' + 1) 3 in > > let headers > List.map ( > -- > 2.25.4ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Reasonably Related Threads
- [v2v PATCH] vCenter: require curl in #precheck
- [PATCH v2v 0/4] v2v: vcenter: Implement cookie scripts.
- [PATCH 5/5] v2v: vCenter: Handle disks with snapshots (RHBZ#1172425).
- [PATCH 0/5] v2v: Handle disks with snapshots (RHBZ#1172425).
- [PATCH] vCenter: pass user name to nbdkit curl plugin