Exemplo n.º 1
0
func TestContentType(t *testing.T) {
	proxy := gopensslproxy.NewProxyHttpServer()
	proxy.OnResponse(gopensslproxy.ContentTypeIs("image/png")).DoFunc(func(resp *http.Response, ctx *gopensslproxy.ProxyCtx) *http.Response {
		resp.Header.Set("X-Shmoopi", "1")
		return resp
	})

	client, l := oneShotProxy(proxy, t)
	defer l.Close()

	for _, file := range []string{"test_data/panda.png", "test_data/football.png"} {
		if resp, err := client.Get(localFile(file)); err != nil || resp.Header.Get("X-Shmoopi") != "1" {
			if err == nil {
				t.Error("pngs should have X-Shmoopi header = 1, actually", resp.Header.Get("X-Shmoopi"))
			} else {
				t.Error("error reading png", err)
			}
		}
	}

	file := "baby.jpg"
	if resp, err := client.Get(localFile(file)); err != nil || resp.Header.Get("X-Shmoopi") != "" {
		if err == nil {
			t.Error("Non png images should NOT have X-Shmoopi header at all", resp.Header.Get("X-Shmoopi"))
		} else {
			t.Error("error reading png", err)
		}
	}
}
Exemplo n.º 2
0
package gopensslproxy_html

import (
	"bytes"
	"errors"
	"io"
	"io/ioutil"
	"net/http"
	"strings"

	"code.google.com/p/go-charset/charset"
	_ "code.google.com/p/go-charset/data"
	"github.com/g3rk6/gopensslproxy"
)

var IsHtml gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/html")

var IsCss gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/css")

var IsJavaScript gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/javascript",
	"application/javascript")

var IsJson gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/json")

var IsXml gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/xml")

var IsWebRelatedText gopensslproxy.RespCondition = gopensslproxy.ContentTypeIs("text/html",
	"text/css",
	"text/javascript", "application/javascript",
	"text/xml",
	"text/json")