unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 3ac649741c3fb00c741bd7f0655938632f13f8cb 3180 bytes (raw)
name: gnu/packages/patches/guile-web.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
From 802a25b1ed5c738aa5f9d3d01f33eb89b22afd1b Mon Sep 17 00:00:00 2001
From: Ludovic Courtès <ludo@gnu.org>
Date: Wed, 15 Jan 2014 22:41:23 +0000
Subject: web: Don't throw if a response is longer than its Content-Length says.

* module/web/response.scm (make-delimited-input-port): Read at most LEN
  bytes from PORT, instead of trying to read more and returning an error
  if more is available.  Try again when 'get-bytevector-n!' return zero.
* test-suite/tests/web-response.test (example-1): Add garbage after the
  body itself.
---
diff --git a/module/web/response.scm b/module/web/response.scm
index 570a2d7..58e3f11 100644
--- a/module/web/response.scm
+++ b/module/web/response.scm
@@ -1,6 +1,6 @@
 ;;; HTTP response objects
 
-;; Copyright (C)  2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
 
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -246,16 +246,21 @@ closes PORT, unless KEEP-ALIVE? is true."
                   bytes-read len))
 
   (define (read! bv start count)
-    (let ((ret (get-bytevector-n! port bv start count)))
-      (if (eof-object? ret)
-          (if (= bytes-read len)
-              0
-              (fail))
-          (begin
-            (set! bytes-read (+ bytes-read ret))
-            (if (> bytes-read len)
-                (fail)
-                ret)))))
+    ;; Read at most LEN bytes in total.  HTTP/1.1 doesn't say what to do
+    ;; when a server provides more than the Content-Length, but it seems
+    ;; wise to just stop reading at LEN.
+    (let ((count (min count (- len bytes-read))))
+      (let loop ((ret (get-bytevector-n! port bv start count)))
+        (cond ((eof-object? ret)
+               (if (= bytes-read len)
+                   0                              ; EOF
+                   (fail)))
+              ((and (zero? ret) (> count 0))
+               ;; Do not return zero since zero means EOF, so try again.
+               (loop (get-bytevector-n! port bv start count)))
+              (else
+               (set! bytes-read (+ bytes-read ret))
+               ret)))))
 
   (define close
     (and (not keep-alive?)
diff --git a/test-suite/tests/web-response.test b/test-suite/tests/web-response.test
index f9679f5..99b1293 100644
--- a/test-suite/tests/web-response.test
+++ b/test-suite/tests/web-response.test
@@ -1,6 +1,6 @@
 ;;;; web-response.test --- HTTP responses       -*- mode: scheme; coding: utf-8; -*-
 ;;;;
-;;;;   Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
+;;;;   Copyright (C) 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -39,7 +39,9 @@ Content-Encoding: gzip\r
 Content-Length: 36\r
 Content-Type: text/html; charset=utf-8\r
 \r
-abcdefghijklmnopqrstuvwxyz0123456789")
+abcdefghijklmnopqrstuvwxyz0123456789
+-> Here is trailing garbage that should be ignored because it is
+   beyond Content-Length.")
 
 (define example-2
   "HTTP/1.1 200 OK\r

debug log:

solving 3ac6497 ...
found 3ac6497 in https://yhetil.org/guix-devel/1390530743-2583-1-git-send-email-tipecaml@gmail.com/

applying [1/1] https://yhetil.org/guix-devel/1390530743-2583-1-git-send-email-tipecaml@gmail.com/
diff --git a/gnu/packages/patches/guile-web.patch b/gnu/packages/patches/guile-web.patch
new file mode 100644
index 0000000..3ac6497

1:24: trailing whitespace.
 
1:27: trailing whitespace.
 
1:32: trailing whitespace.
 
1:59: trailing whitespace.
 
1:82: trailing whitespace.
 
Checking patch gnu/packages/patches/guile-web.patch...
Applied patch gnu/packages/patches/guile-web.patch cleanly.
warning: 5 lines add whitespace errors.

index at:
100644 3ac649741c3fb00c741bd7f0655938632f13f8cb	gnu/packages/patches/guile-web.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).