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.
 
 
 

59 lines
2.0 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 martian provides an HTTP/1.1 proxy with an API for configurable
  15. // request and response modifiers.
  16. package martian
  17. import "net/http"
  18. // RequestModifier is an interface that defines a request modifier that can be
  19. // used by a proxy.
  20. type RequestModifier interface {
  21. // ModifyRequest modifies the request.
  22. ModifyRequest(req *http.Request) error
  23. }
  24. // ResponseModifier is an interface that defines a response modifier that can
  25. // be used by a proxy.
  26. type ResponseModifier interface {
  27. // ModifyResponse modifies the response.
  28. ModifyResponse(res *http.Response) error
  29. }
  30. // RequestResponseModifier is an interface that is both a ResponseModifier and
  31. // a RequestModifier.
  32. type RequestResponseModifier interface {
  33. RequestModifier
  34. ResponseModifier
  35. }
  36. // RequestModifierFunc is an adapter for using a function with the given
  37. // signature as a RequestModifier.
  38. type RequestModifierFunc func(req *http.Request) error
  39. // ResponseModifierFunc is an adapter for using a function with the given
  40. // signature as a ResponseModifier.
  41. type ResponseModifierFunc func(res *http.Response) error
  42. // ModifyRequest modifies the request using the given function.
  43. func (f RequestModifierFunc) ModifyRequest(req *http.Request) error {
  44. return f(req)
  45. }
  46. // ModifyResponse modifies the response using the given function.
  47. func (f ResponseModifierFunc) ModifyResponse(res *http.Response) error {
  48. return f(res)
  49. }