Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to add custom metadata to Response #1877

Closed
kmike opened this issue Mar 24, 2016 · 4 comments · Fixed by #5218 · May be fixed by #5131
Closed

Allow to add custom metadata to Response #1877

kmike opened this issue Mar 24, 2016 · 4 comments · Fixed by #5218 · May be fixed by #5131
Labels

Comments

@kmike
Copy link
Member

kmike commented Mar 24, 2016

Currently it is not possible to attach a custom attribute to Response in a middleware because replace method won't keep it. There are workarounds (e.g. putting objects to response.flags), but they are ugly.

What do you think about adding an attribute to Response where user can put anything, similar to Request.meta?

@kmike kmike added the discuss label Mar 24, 2016
@kmike
Copy link
Member Author

kmike commented Mar 24, 2016

Almost the same issue: #1453

@kmike
Copy link
Member Author

kmike commented Mar 28, 2016

One workaround is to create custom Response subclasses and use response.replace(cls=MyCustomResponse) in a middleware.

The problem with this solution is that Scrapy sometimes constructs responses by itself, e.g. when retreiving from HTTP cache or when handling decompression. In this case original response class gets forgotten.

@joeharrison714
Copy link

I'd like to try to implement this, does anyone have any newer thoughts about it that could lead me in the right direction?

@Gallaecio
Copy link
Member

#5131 seems to address this when defining Response.attributes and using it from replace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants