-
Notifications
You must be signed in to change notification settings - Fork 38
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
Parse incoming JSON in POST body #377
Comments
Sounds good to me. |
I... don't understand your requirements. Why is this not just:
|
@pjz |
JSON isn't really web-spec. It's common, but not specified in any part of HTTP anywhere. I'd be against special-casing it. OTOH, I'd be all about figuring out some way to set up a general-case handler for arbitrary content-types. A way to specify "if the content-type of the POST body is application/json, run it through this handler and store the result in this variable." Hm, probably want that to be site-wide instead of per-endpoint, eh? So it could be an algorithm hook:
Put the above into your algorithm stack somewhere in the request-handling sequence and you should be GTG. |
P.S. I'd be all for implementing body parsing in an algorithm function (that'd be part of "flatten algorithm further" in our roadmap; #357). In that case it seems that we should do the same with the existing special cases. Then the question is what body parsers we ship in our stock algorithm, and I think we should include an |
Agreed! I think the request object should probably have a little registry where you can register content-type handlers or something. |
Well, there should be a registry somewhere, at any rate. Maybe the request object? Oh, no, it's site wide. Probably the website object. |
A registry seems like a simple and performant method to me. Something like:
|
That sounds okay... but where should the result be put? That's going to require some management to avoid collisions in the website object's main namespace. |
What do we do now? Don't we use |
Ah, hmm. Yeah, that could work, though it looks like it may require some metaclass hacking or something to replicate the current functionality. |
Actually we'll have to change the current API a little; instead of |
I think I prefer |
Hmm. I like giving access, but what happens if a body_parser doesn't set
|
Why would a body parser set
Not really, the parser just has to call Here's what I'm thinking:
|
If the parser reads the socket then the user can't, and vice versa. By pre-emptively reading the socket and storing the result in I do like the |
Me neither, but it is possible to have both, by first reading |
request.body is now the result of running the appropriate body_parser (based on content-type header) over request.raw_body Inlined the functionality of context.py into the dynamic_resource object
request.body is now the result of running the appropriate body_parser (based on content-type header) over request.raw_body Inlined the functionality of context.py into the dynamic_resource object
Like that, @Changaco ? |
#379 isn't exactly what I proposed:
but aside from that it looks okay. |
Should the |
If |
okay, fixed in the latest version of #379 |
Fix #377: Reify body_parsers and make request.body dynamic
HI i am facing an issue whe i have migrated code from my local system to AWS RawPostDataException at /users/ It seems i can't access request.method and request.data in views.py simulteneously. It would be great if you can suggest some work around for this issue |
If you meant to post this as an issue, you should open a new one, not revive one that's over a year old. Also, you should include more detail, up to and including simplified code exemplifying your problem. |
A quick web search shows that |
request.body is now the result of running the appropriate body_parser (based on content-type header) over request.raw_body Inlined the functionality of context.py into the dynamic_resource object
Fix #377: Reify body_parsers and make request.body dynamic
I'm implementing a simplate to receive webhook callbacks which are
POST
requests with JSON data in the body (andContent-Type: application/json
in the headers). Adding support for JSON in Aspen'sBody._parse()
function could make it slightly easier to write such simplates. What do you think ?The text was updated successfully, but these errors were encountered: