Comments (14)
Seems like it's the duty of koa. that.request.is() hasn't return the form type.
from hela.
@daiwhea Hi, very thanks!
New release is coming - working on store-cache
, ip-filter
and kind-error
locally.
But yea, it is koa related issue, especially https://github.com/jshttp/type-is.
Actually.. When I think, you can give custom error types to koa-better-body
options, but.. hm. Currently that is not so flexible.
So one way is to set text/html
in the opts.extendTypes.form
array, other to allow opts.extendTypes
to be array and pass it directly to request.is()
I'll mark it as todo
Cheers,
from hela.
Hm. Actually, try
var opts = {
extendTypes: {
form: ['x-www-form-urlencoded', 'text/html']
}
}
I guess it should work, currently.
from hela.
Thank you. I have tried but it doesn't work.
var opts = {
extendTypes: {
form: ['x-www-form-urlencoded', 'text/html']
}
}
Now I use an ugly use() in the top of app.js. But it's not that cute!
app.use(function* (next) {
if (this.request.header['content-type'] == 'application/x-www-form-urlencoded; text/html; charset=utf-8') {
this.request.header['content-type'] = 'application/x-www-form-urlencoded';
}
yield next;
});
from hela.
Hm, interesting. I'll review type-is
and will PR there if needed.
from hela.
@daiwhea, would you try these
var opts = {
extendTypes: {
form: ['x-www-form-urlencoded', 'html']
}
}
// and
var opts = {
extendTypes: {
form: ['application/x-www-form-urlencoded', 'text/html']
}
}
I'm curious why it not work. And cant test it at the moment.
ref: koa.request docs I guess, cuz they both should be written in one style.
from hela.
I am also curious why is this header application/x-www-form-urlencoded; text/html; charset=utf-8
, how it comes? I mean.. when form is submitted it is urlencoded
, not text/html
, if i remember?
Maybe an issue is on your side, on app side.
from hela.
Other than that... yea I should rush the process of incoming release, because a lot of things was changed from last updates.
from hela.
Thank you!
Both won't work. This header comes from the greatest alipay notify. Alipay is an online payment api used in China.
In order to test, I used an use() to force the request.header['content-type'] = 'application/x-www-form-urlencoded; text/html; charset=utf-8'; of course it's only for locally testing.
app.use(function* log_raw_request(next) {
this.request.header['content-type'] = 'application/x-www-form-urlencoded; text/html; charset=utf-8';
console.log('log_raw_request was called',this.request.header['content-type'],this.request);
yield next;
});
from hela.
Mm, okey, thanks.
Also, you can use this.set
to set the headers in koa.
from hela.
Thanks. Will this.set() just set the koa.response headers? I need to set the request.header.
from hela.
O yea yea.
koa.response headers
this.set sets the response, my mistake.
from hela.
Thank you sir.
I have visited jshttp/type-is#16 , and they have closed that issue. Yes, it's the duty of alipay api. But we cannot change it.
I also viewed your koa-better-body/index.js ["version": "1.0.17"] on line 105. There are 3 judgements. When alipay header comes, there is no judgement will be entered. Can we append the raw body in the last else branch?
if (that.request.is(opts.extendTypes.json)) {
cache.fields = yield parse.json(that, options);
} else if (that.request.is(opts.extendTypes.form)) {
options.limit = opts.formLimit;
cache.fields = yield parse.form(that, options);
} else if (opts.multipart && that.request.is(opts.extendTypes.multipart)) {
cache = yield parse.multipart(that, opts.formidable);
} else {
console.log('not parsed');
// should we add raw body here?
}
from hela.
I think this is resolved in refactor branch. More at #34.
from hela.
Related Issues (20)
- support for ts HOT 5
- Body or fields not reflecting the data passed in request params for route type DELETE HOT 2
- actory HOT 1
- koa deprecated Support for generators will be removed in v3. HOT 3
- How to save uploaded files in folder which name is session id in cookie? HOT 1
- koa-body-parser version using git url HOT 1
- Weekly Digest (10 February, 2019 - 17 February, 2019)
- Weekly Digest (17 February, 2019 - 24 February, 2019)
- Weekly Digest (24 February, 2019 - 3 March, 2019)
- Weekly Digest (3 March, 2019 - 10 March, 2019)
- tunnckoCore/body-parsers doesn' HOT 1
- Announcement: Migration to monorepo. Important, please read! HOT 1
- it doesn't work with latest egg.js HOT 1
- sasa
- eslint: implement RFC#9
- eslint: engine.isPathIgnored is perf hit of ~1sec
- hela/yaro switch to `sywac` or `yargs` or `cac` HOT 1
- bug in parse() HOT 1
- npm i koa-better-body is install error HOT 1
- ctx.request.body returns undefined HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hela.