@@ -29,7 +29,7 @@ type SimpleRouter struct {
2929 httpClient httputil.Client
3030}
3131
32- func (r * SimpleRouter ) BuildPath (method , path string , query url.Values , nodes []* model.NodeEndpointCache , body []byte ) (map [common.Address ]model.RequestMeta , error ) {
32+ func (r * SimpleRouter ) BuildPath (method , path string , query url.Values , nodes []* model.NodeEndpointCache , body []byte , isRssNode bool ) (map [common.Address ]model.RequestMeta , error ) {
3333 if method == http .MethodGet && query != nil {
3434 path = fmt .Sprintf ("%s?%s" , path , query .Encode ())
3535 }
@@ -53,6 +53,7 @@ func (r *SimpleRouter) BuildPath(method, path string, query url.Values, nodes []
5353 Endpoint : fullURL ,
5454 AccessToken : node .AccessToken ,
5555 Body : body ,
56+ IsRssNode : isRssNode ,
5657 }
5758 }
5859
@@ -113,9 +114,7 @@ func (r *SimpleRouter) distribute(ctx context.Context, nodeMap map[common.Addres
113114
114115 response := & model.DataResponse {Address : address , Endpoint : requestMeta .Endpoint }
115116 // Fetch the data from the Node.
116- body , _ , err := r .httpClient .FetchWithMethod (ctx , requestMeta .Method , requestMeta .Endpoint , requestMeta .AccessToken , bytes .NewReader (requestMeta .Body ))
117-
118- // todo deal headers
117+ body , headers , err := r .httpClient .FetchWithMethod (ctx , requestMeta .Method , requestMeta .Endpoint , requestMeta .AccessToken , bytes .NewReader (requestMeta .Body ))
119118
120119 if err != nil {
121120 zap .L ().Error ("failed to fetch request" , zap .String ("node" , address .String ()), zap .Error (err ))
@@ -132,35 +131,41 @@ func (r *SimpleRouter) distribute(ctx context.Context, nodeMap map[common.Addres
132131
133132 response .Err = readErr
134133 } else {
135- var v interface {}
136- err = json .Unmarshal (data , & v )
137-
138- if err != nil {
139- zap .L ().Error ("failed to unmarshal response body" , zap .String ("node" , address .String ()), zap .Error (err ))
140-
141- response .Err = fmt .Errorf ("invalid data" )
142- }
143-
144- if _ , ok := v .([]interface {}); ok {
145- zap .L ().Info ("response is an array" , zap .String ("node" , address .String ()))
146-
134+ if requestMeta .IsRssNode {
147135 response .Data = data
136+ response .IsRssNode = requestMeta .IsRssNode
137+ response .Etag = headers .Get ("Etag" )
148138 } else {
149- activity := & model. ActivityResponse {}
150- activities := & model. ActivitiesResponse {}
139+ var v interface {}
140+ err = json . Unmarshal ( data , & v )
151141
152- // Check if the Node's data is valid.
153- if ! validateData (data , activity ) && ! validateData (data , activities ) {
154- zap .L ().Error ("failed to parse response" , zap .String ("node" , address .String ()))
142+ if err != nil {
143+ zap .L ().Error ("failed to unmarshal response body" , zap .String ("node" , address .String ()), zap .Error (err ))
155144
156145 response .Err = fmt .Errorf ("invalid data" )
157- } else {
158- // If the data is non-null, set the result as valid.
159- if activity .Data != nil || activities .Data != nil {
160- response .Valid = true
161- }
146+ }
147+
148+ if _ , ok := v .([]interface {}); ok {
149+ zap .L ().Info ("response is an array" , zap .String ("node" , address .String ()))
162150
163151 response .Data = data
152+ } else {
153+ activity := & model.ActivityResponse {}
154+ activities := & model.ActivitiesResponse {}
155+
156+ // Check if the Node's data is valid.
157+ if ! validateData (data , activity ) && ! validateData (data , activities ) {
158+ zap .L ().Error ("failed to parse response" , zap .String ("node" , address .String ()))
159+
160+ response .Err = fmt .Errorf ("invalid data" )
161+ } else {
162+ // If the data is non-null, set the result as valid.
163+ if activity .Data != nil || activities .Data != nil {
164+ response .Valid = true
165+ }
166+
167+ response .Data = data
168+ }
164169 }
165170 }
166171 }
0 commit comments