fill metadata early
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		
							
								
								
									
										22
									
								
								handler.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								handler.go
									
									
									
									
									
								
							| @@ -81,7 +81,15 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ctx := metadata.NewIncomingContext(r.Context(), nil) | 	ctx := context.WithValue(r.Context(), rspCodeKey{}, &rspCodeVal{}) | ||||||
|  | 	md, ok := metadata.FromIncomingContext(ctx) | ||||||
|  | 	if !ok { | ||||||
|  | 		md = metadata.New(len(r.Header)) | ||||||
|  | 	} | ||||||
|  | 	for k, v := range r.Header { | ||||||
|  | 		md.Set(k, strings.Join(v, ", ")) | ||||||
|  | 	} | ||||||
|  | 	ctx = metadata.NewIncomingContext(ctx, md) | ||||||
|  |  | ||||||
| 	defer r.Body.Close() | 	defer r.Body.Close() | ||||||
|  |  | ||||||
| @@ -136,15 +144,6 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	md, ok := metadata.FromIncomingContext(ctx) |  | ||||||
| 	if !ok { |  | ||||||
| 		md = metadata.New(0) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for k, v := range r.Header { |  | ||||||
| 		md.Set(k, strings.Join(v, ", ")) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// get fields from url values | 	// get fields from url values | ||||||
| 	if len(r.URL.RawQuery) > 0 { | 	if len(r.URL.RawQuery) > 0 { | ||||||
| 		umd, cerr := rflutil.URLMap(r.URL.RawQuery) | 		umd, cerr := rflutil.URLMap(r.URL.RawQuery) | ||||||
| @@ -203,13 +202,12 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||||||
| 		method:      fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name), | 		method:      fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name), | ||||||
| 		body:        b, | 		body:        b, | ||||||
| 		payload:     argv.Interface(), | 		payload:     argv.Interface(), | ||||||
|  | 		header:      md, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var scode int | 	var scode int | ||||||
| 	// define the handler func | 	// define the handler func | ||||||
| 	fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) { | 	fn := func(fctx context.Context, req server.Request, rsp interface{}) (err error) { | ||||||
| 		fctx = context.WithValue(fctx, rspCodeKey{}, &rspCodeVal{}) |  | ||||||
| 		fctx = metadata.NewIncomingContext(fctx, md) |  | ||||||
| 		returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(fctx), reflect.ValueOf(argv.Interface()), reflect.ValueOf(rsp)}) | 		returnValues = function.Call([]reflect.Value{hldr.rcvr, hldr.mtype.prepareContext(fctx), reflect.ValueOf(argv.Interface()), reflect.ValueOf(rsp)}) | ||||||
|  |  | ||||||
| 		scode = GetRspCode(fctx) | 		scode = GetRspCode(fctx) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user