コード例 #1
0
ファイル: endpoint.go プロジェクト: mondough/mercury
func (e Endpoint) unmarshaler(req mercury.Request) tmsg.Unmarshaler {
	result := marshaling.Unmarshaler(req.Headers()[marshaling.ContentTypeHeader], e.Request)
	if result == nil { // Default to json
		result = marshaling.Unmarshaler(marshaling.JSONContentType, e.Request)
	}
	return result
}
コード例 #2
0
ファイル: middleware.go プロジェクト: robmurtha/mercury
func (m requestTreeMiddleware) ProcessClientRequest(req mercury.Request) mercury.Request {
	if req.Headers()[parentIdHeader] == "" { // Don't overwrite an exiting header
		if parentId, ok := req.Context().Value(reqIdCtxKey).(string); ok && parentId != "" {
			req.SetHeader(parentIdHeader, parentId)
		}
	}

	// Pass through the current service and endpoint as the origin of this request
	req.SetHeader(originServiceHeader, CurrentServiceFor(req))
	req.SetHeader(originEndpointHeader, CurrentEndpointFor(req))

	return req
}
コード例 #3
0
ファイル: message.go プロジェクト: mondough/mercury
func old2NewRequest(oldReq mercury.Request) typhon.Request {
	ep := oldReq.Endpoint()
	if !strings.HasPrefix(ep, "/") {
		ep = "/" + ep
	}
	v := typhon.Request{
		Context: oldReq.Context(),
		Request: http.Request{
			Method: "POST",
			URL: &url.URL{
				Scheme: "http",
				Host:   oldReq.Service(),
				Path:   ep},
			Proto:         "HTTP/1.1",
			ProtoMajor:    1,
			ProtoMinor:    1,
			Header:        toHeader(oldReq.Headers()),
			Host:          oldReq.Service(),
			Body:          ioutil.NopCloser(bytes.NewReader(oldReq.Payload())),
			ContentLength: int64(len(oldReq.Payload()))}}
	v.Header.Set(legacyIdHeader, oldReq.Id())
	return v
}
コード例 #4
0
ファイル: middleware.go プロジェクト: robmurtha/mercury
func (m requestTreeMiddleware) ProcessServerRequest(req mercury.Request) (mercury.Request, mercury.Response) {
	req.SetContext(context.WithValue(req.Context(), reqIdCtxKey, req.Id()))
	if v := req.Headers()[parentIdHeader]; v != "" {
		req.SetContext(context.WithValue(req.Context(), parentIdCtxKey, v))
	}

	// Set the current service and endpoint into the context
	req.SetContext(context.WithValue(req.Context(), currentServiceHeader, req.Service()))
	req.SetContext(context.WithValue(req.Context(), currentEndpointHeader, req.Endpoint()))

	// Set the originator into the context
	req.SetContext(context.WithValue(req.Context(), originServiceHeader, req.Headers()[originServiceHeader]))
	req.SetContext(context.WithValue(req.Context(), originEndpointHeader, req.Headers()[originEndpointHeader]))

	return req, nil
}
コード例 #5
0
ファイル: endpoint.go プロジェクト: robmurtha/mercury
func (e Endpoint) unmarshaler(req mercury.Request) tmsg.Unmarshaler {
	return marshaling.Unmarshaler(req.Headers()[marshaling.ContentTypeHeader], e.Request)
}