Beispiel #1
0
func (t *Transaction) MarshalJSON() ([]byte, error) {
	var topts string

	reqopts := t.ReqOptions
	if reqopts&CLEAR_COOKIES > 0 {
		topts += "CLEAR_COOKIES "
	} else {
		t.Cookies = utils.MapMerge(t.Cookies, t.conquest.Initials["Cookies"],
			false)
	}

	if reqopts&CLEAR_HEADERS > 0 {
		topts += "CLEAR_HEADERS "
	} else {
		t.Headers = utils.MapMerge(t.Headers, t.conquest.Initials["Headers"],
			false)
	}
	if reqopts&REJECT_COOKIES > 0 {
		topts += "REJECT_COOKIES "
	}

	res := struct {
		Options, Header  string
		Conditions, Body map[string]interface{}
	}{
		Options:    topts,
		Conditions: t.ResConditions,
		Body:       t.Body,
	}

	res.Header = t.Verb + " " + t.Path + " " + t.conquest.Proto + "\r\n"
	res.Header += "Host: " + t.conquest.Host + "\r\n"

	if len(t.Headers) > 0 {
		for k, v := range t.Headers {
			if _, ok := v.(string); !ok {
				continue
			}
			res.Header += k + ": " + v.(string) + "\r\n"
		}
	}

	if len(t.Cookies) > 0 {
		res.Header += "Cookie: "
		for k, v := range t.Cookies {
			if _, ok := v.(string); !ok {
				continue
			}
			res.Header += k + "=" + v.(string) + "; "
		}
		res.Header += "\r\n"
	}
	return json.Marshal(&res)
}
Beispiel #2
0
// conquest.prototype.ConquestHeaders()
// Adds browser-like headers
// Ex: conquest.ConquestHeaders();
func (c JSConquest) ConquestHeaders(call otto.FunctionCall) otto.Value {
	if _, ok := c.conquest.Initials["Headers"]; !ok {
		c.conquest.Initials["Headers"] = map[string]interface{}{}
	}

	c.conquest.Initials["Headers"] = utils.MapMerge(
		c.conquest.Initials["Headers"], map[string]interface{}{
			"User-Agent":    "conquest " + VERSION,
			"Connection":    "keep-alive",
			"Cache-Control": "no-cache",
			"Pragma":        "no-cache",
		}, false)
	return toOttoValueOrPanic(c.vm, c)
}