Skip to content

Commit

Permalink
fix: do not copy request headers in response
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineRR committed Feb 27, 2023
1 parent b1c580f commit 9f3f7f2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ def sync_decorator_view():
def get():
return "Hello, world!"

def post(request):
body = bytearray(request["body"]).decode("utf-8")
def post(request: Request):
body = request.body.content
return {"status_code": 200, "body": body}


Expand All @@ -540,8 +540,8 @@ def async_decorator_view():
async def get():
return "Hello, world!"

async def post(request):
body = bytearray(request["body"]).decode("utf-8")
async def post(request: Request):
body = request.body.content
return {"status_code": 200, "body": body}


Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_binary_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from http_methods_helpers import get
from helpers.http_methods_helpers import get

BASE_URL = "http://127.0.0.1:8080"

Expand Down
2 changes: 0 additions & 2 deletions integration_tests/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@pytest.mark.parametrize("function_type", ["sync", "async"])
def test_middlewares(function_type: str, session):
r = get(f"/{function_type}/middlewares")
assert "before" in r.headers
assert r.headers["before"] == f"{function_type}_before_request"
assert "after" in r.headers
assert r.headers["after"] == f"{function_type}_after_request"
assert r.text == f"{function_type} middlewares after"
7 changes: 5 additions & 2 deletions integration_tests/views/async_view.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from robyn.robyn import Request


def AsyncView():
async def get():
return "Hello, world!"

async def post(request):
body = bytes(request["body"]).decode("utf-8")
async def post(request: Request):
body = request.body.content
return {
"status": 200,
"body": body,
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/views/sync_view.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from robyn.robyn import Request


def SyncView():
def get():
return "Hello, world!"

def post(request):
body = bytes(request["body"]).decode("utf-8")
def post(request: Request):
body = request.body.content
return {
"status": 200,
"body": body,
Expand Down
6 changes: 5 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ async fn index(
Response::not_found(&request.headers)
};

response.headers.extend(request.headers.into_iter());
response.headers.extend(
global_response_headers
.iter()
.map(|elt| (elt.key().clone(), elt.value().clone())),
);

// After middleware
response = match middleware_router.get_route(&MiddlewareRoute::AfterRequest, req.uri().path()) {
Expand Down

0 comments on commit 9f3f7f2

Please sign in to comment.