Giter VIP home page Giter VIP logo

Comments (8)

SlyMarbo avatar SlyMarbo commented on September 28, 2024

Could you give some more details?

  • What headers did you get when you used http.ListenAndServeTLS?
  • Where are these headers being printed from?

Thanks

from spdy.

keichan34 avatar keichan34 commented on September 28, 2024

Reverse-proxied headers sent to www.google.com when using http.ListenAndServeTLS:

GET / HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cache-Control: max-age=0
X-Forwarded-For: 127.0.0.1
Host: www.google.com

I'm getting the headers by using Charles as a reverse-proxy to www.google.com, but I've been able to reproduce using a simple HTTP server that prints out the headers, too.

from spdy.

SlyMarbo avatar SlyMarbo commented on September 28, 2024

As I understand it, the main issue is the difference between :host and Host. I'll look into why this is happening. It's also odd that the X-Forwarded-For header is different, but that's not set by my library, so I think that's just an oddity of SpdyLay.

Is there something else I'm missing?

from spdy.

keichan34 avatar keichan34 commented on September 28, 2024

Ah, sorry, I used Chrome because SpdyLay doesn't support regular HTTPS connections (it's a SPDY debugging tool: https://github.com/tatsuhiro-t/spdylay). Trying again with curl works:

$ curl https://localhost:5005/
GET / HTTP/1.1
User-Agent: curl/7.30.0
Accept: */*
X-Forwarded-For: ::1
Accept-Encoding: gzip
Host: www.google.com

My understanding is that, for some reason, the lines that start with ": " aren't actually supposed to be there...?

from spdy.

SlyMarbo avatar SlyMarbo commented on September 28, 2024

Those are headers new to SPDY. The :host, :method, :path, :scheme, and :version headers must be included in SPDY requests, since they build up the data that would be in an HTTP request line (GET / HTTP/1.1).

All ok?

from spdy.

keichan34 avatar keichan34 commented on September 28, 2024

Oh, I understand now. So, it's sending SPDY headers to the HTTP backend set up in httputil.NewSingleHostReverseProxy... Is that expected behavior?

from spdy.

SlyMarbo avatar SlyMarbo commented on September 28, 2024

That's the behavior exhibited by httputil.NewSingleHostReverseProxy. Since it's that code that creates the outward-bound request, it's up to that whether to forward the new headers. However, if I remember correctly, they're still valid HTTP headers, so it shouldn't do any harm to forward them on.

If you don't want to forward the SPDY headers, I suggest writing code similar to the following:

targetURL := url.Parse("http://www.google.com")
reverseProxy := httputil.NewSingleHostReverseProxy(targetURL)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  for key := range r.Header {
    if strings.HasPrefix(key, ":") {
      r.Header.Del(key)
    }
  }
  reverseProxy.ServeHTTP(w, r)
})
if err = spdy.ListenAndServeTLS(":5005", "cert.pem", "key.pem", nil); err != nil {
  // handle error.
  log.Fatal(err)
}

from spdy.

keichan34 avatar keichan34 commented on September 28, 2024

Ah, I see now. Thanks a lot for your time!

from spdy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.