Skip to content

Commit

Permalink
feat: pass request-headers as metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
NarekA committed Dec 7, 2023
1 parent 129b7b3 commit a8098f2
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 149 deletions.
1 change: 1 addition & 0 deletions jina/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
__args_executor_func__ = {
'docs',
'parameters',
'metadata',
'docs_matrix',
}
__args_executor_init__ = {'metas', 'requests', 'runtime_args'}
Expand Down
6 changes: 6 additions & 0 deletions jina/proto/docarray_v1/jina.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ message DataRequestProto {
}

DataContentProto data = 4; // container for docs and groundtruths

google.protobuf.Struct metadata = 5; // extra kwargs that will be used in executor
}


Expand All @@ -138,6 +140,8 @@ message SingleDocumentRequestProto {

docarray.DocumentProto document = 4; // the document in this request

google.protobuf.Struct metadata = 5; // extra kwargs that will be used in executor

}

message DataRequestProtoWoData {
Expand All @@ -148,6 +152,8 @@ message DataRequestProtoWoData {

repeated RouteProto routes = 3; // status info on every routes

google.protobuf.Struct metadata = 4; // extra kwargs that will be used in executor

}


Expand Down
92 changes: 46 additions & 46 deletions jina/proto/docarray_v1/pb/jina_pb2.py

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions jina/proto/docarray_v1/pb2/jina_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ def add_post_route(
)
app_kwargs['response_class'] = DocArrayResponse

from fastapi import Request

@app.api_route(**app_kwargs)
async def post(body: input_model, response: Response):
async def post(body: input_model, response: Response, request: Request):
target_executor = None
req_id = None
if body.header is not None:
Expand All @@ -208,6 +210,11 @@ async def post(body: input_model, response: Response):
docs,
exec_endpoint=endpoint_path,
parameters=body.parameters,
metadata=dict(
request.headers or {
"no_headers": "true"
}
),
target_executor=target_executor,
request_id=req_id,
return_results=True,
Expand Down Expand Up @@ -245,8 +252,6 @@ def add_streaming_routes(
endpoint_path,
input_doc_model=None,
):
from fastapi import Request

@app.api_route(
path=f'/{endpoint_path.strip("/")}',
methods=['GET'],
Expand Down
Loading

0 comments on commit a8098f2

Please sign in to comment.