Skip to content
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

Responses with a status code of 204 are not made according to spec #865

Closed
albertov opened this issue Jul 11, 2019 · 2 comments
Closed

Responses with a status code of 204 are not made according to spec #865

albertov opened this issue Jul 11, 2019 · 2 comments
Labels
Milestone

Comments

@albertov
Copy link

Description of the bug

According to the RFC7230 (http://tools.ietf.org/html/rfc7230#section-3.3.1):

A server MUST NOT send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content).

hoverfly seems to break this restriction when using https (at least) which may break clients (eg: snoyberg/http-client#408)

Steps to reproduce the issue

Add this pair to a simulation.json, hoverctl import it, set hoverfly in simulate mode (hoverctl mode simulate) and use the proxy with a client that gives no leeway (eg: http-client)

{
                                "request": {
                                        "path": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "/auth/tokens/jack-test-2"
                                                }
                                        ],
                                        "method": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "GET"
                                                }
                                        ],
                                        "destination": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "example.com"
                                                }
                                        ],
                                        "scheme": [
                                                {
                                                        "matcher": "exact",
                                                        "value": "https"
                                                }
                                        ],
                                        "body": [
                                                {
                                                        "matcher": "exact",
                                                        "value": ""
                                                }
                                        ]
                                },
                                "response": {
                                        "status": 204,
                                        "encodedBody": false,
                                        "headers": {
                                                "Connection": [
                                                        "keep-alive"
                                                ],
                                                "Content-Type": [
                                                        "application/json;charset=utf-8"
                                                ],
                                                "Date": [
                                                        "Mon, 08 Jul 2019 15:04:19 GMT"
                                                ],
                                                "Hoverfly": [
                                                        "Was-Here"
                                                ],
                                                "Server": [
                                                        "nginx/1.15.8"
                                                ],
                                                "Strict-Transport-Security": [
                                                        "max-age=15724800; includeSubDomains"
                                                ]
                                        },
                                        "templated": false
                                }
                        }

Observed result

Hoverfly error messages seen (If none, say none)

none

If possible, add screenshots to help explain your problem

A decrypted dump of the response given by Hoverfly with request/response pair given above:

image

The response body (highlighted) is 0\r\n\r\n which appear to be the chunk header for 0-sized chunk (\0\r\n) and the empty terminated chunk itself (\r\n)

Expected result

The responses with 204 status code and 1xx shouldn't have the transfer-encoding: chunked header nor perform that encoding on the empty response body.

Additional relevant information

  1. Hoverfly version: cd51f9d with a patch to dump the private key to be able to decode the traffic with wireshark:
diff --git a/vendor/github.com/SpectoLabs/goproxy/signer.go b/vendor/github.com/SpectoLabs/goproxy/signer.go
index f6d99fc7..69d9de21 100644
--- a/vendor/github.com/SpectoLabs/goproxy/signer.go
+++ b/vendor/github.com/SpectoLabs/goproxy/signer.go
@@ -11,6 +11,9 @@ import (
        "runtime"
        "sort"
        "time"
+        "os"
+        "fmt"
+        "encoding/pem"
 )
 
 func hashSorted(lst []string) []byte {
@@ -76,6 +79,13 @@ func signHost(ca tls.Certificate, hosts []string) (cert tls.Certificate, err err
        if certpriv, err = rsa.GenerateKey(&csprng, 1024); err != nil {
                return
        }
+        pemPrivateFile, err := os.Create(hosts[0]+".private_key.pem")
+        if err != nil {
+            fmt.Println(err)
+            os.Exit(1)
+        }
+        pem.Encode(pemPrivateFile, &pem.Block{Type: "RSA PRIVATE KEY", Bytes:x509.MarshalPKCS1PrivateKey(certpriv) })
+        pemPrivateFile.Close()
        var derBytes []byte
        if derBytes, err = x509.CreateCertificate(&csprng, &template, x509ca, &certpriv.PublicKey, ca.PrivateKey); err != nil {
                return
  1. Anything that might help us to diagnose the problem
@tommysitu
Copy link
Member

Thank you for the detailed diagnostic report provided. Hoverfly undoubtedly has gaps in meeting the RFC7230 spec. We will look into this one.

@tommysitu tommysitu added the bug label Jul 11, 2019
@tommysitu tommysitu added this to the v1.1.1 milestone Jul 11, 2019
@tommysitu
Copy link
Member

Fixed in v1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants