You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.6 KiB

  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package httpspec provides a modifier stack that has been preconfigured to
  15. // provide spec-compliant HTTP proxy behavior.
  16. //
  17. // Related: https://www.mnot.net/blog/2011/07/11/what_proxies_must_do
  18. package httpspec
  19. import (
  20. "github.com/google/martian/fifo"
  21. "github.com/google/martian/header"
  22. )
  23. // NewStack returns a martian modifier stack that handles ensuring proper proxy
  24. // behavior, in addition to a fifo.Group that can be used to add additional
  25. // modifiers within the stack.
  26. func NewStack(via string) (outer *fifo.Group, inner *fifo.Group) {
  27. outer = fifo.NewGroup()
  28. hbhm := header.NewHopByHopModifier()
  29. outer.AddRequestModifier(hbhm)
  30. outer.AddRequestModifier(header.NewForwardedModifier())
  31. outer.AddRequestModifier(header.NewBadFramingModifier())
  32. vm := header.NewViaModifier(via)
  33. outer.AddRequestModifier(vm)
  34. inner = fifo.NewGroup()
  35. outer.AddRequestModifier(inner)
  36. outer.AddResponseModifier(inner)
  37. outer.AddResponseModifier(vm)
  38. outer.AddResponseModifier(hbhm)
  39. return outer, inner
  40. }