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