Comments (7)
Looking at undici's code now, it looks like their IncomingHttpHeaders
type is not from node:http; it's homegrown. It's just Record<string, string | string[] | undefined>
. That's not compatible with urllib's (node:http's) IncomingHttpHeaders
type.
from urllib.
http server can response set-cookie
headers many times.
from urllib.
Yes, I know.
I'll try to explain differently.
If the server sends more than one set-cookie
header, res.headers["set-cookie"]
is an array of strings. This is fine.
If the server sends just one set-cookie
header, res.headers["set-cookie"]
is a single string. This disagrees with the typescript type associated with res.headers["set-cookie"]
, which is string | undefined
(which it gets from IncomingHttpHeaders
from node:http
). string[]
is not assignable to string | undefined
. So either the types are wrong, or there is a bug in the code. This means I can get errors in my code which Typescript cannot see.
Undici can also return a single string for that property, but that is not a problem since it reports the types differently. It associates type string | string[] | undefined
with that property. It is not using IncomingHttpHeaders
from node:http
, but rather its own type which it also calls IncomingHttpHeaders
. The two IncomingHttpHeaders
types are not compatible.
from urllib.
I would follow the undici IncomingHttpHeaders fix it.
from urllib.
https://github.com/nodejs/undici/blob/b0d3ca7701766b6cb9ebb8fed7dd08d3a684b91b/types/header.d.ts#L4
the undici IncomingHttpHeaders is a simple version of node:http IncomingHttpHeaders, I think the node:http IncomingHttpHeaders is better and more types defines.
from urllib.
I agree. If you see the issue I linked to above, you'll see that at some point they planned to switch to node's type, but as far as I can tell they never got around to it.
But the fact is, what you're providing on res.headers
is undici's type, but in your types you're declaring that it's node's type. You either need to fix the data so it matches the node type, or change the type declarations to be the same as undici's. Maybe you can import the relevant type straight from undici rather than recreating it; that way you shouldn't then need to change it again once they change their types.
I suppose a 3rd option would be to provide a patch to undici so that they are using node's types. But they wouldn't release that until a major version change.
from urllib.
#471 will close it.
@tremby Thanks for the big help message.
from urllib.
Related Issues (20)
- ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time HOT 2
- diagnostics_channel should be a dependency in version 3.3.1 HOT 2
- Digest Auth fails when server provides multiple algorithms
- change the default highWaterMark on http request HOT 5
- add FormData demo and unittest
- use --moduleResolution bundler to fix esm import HOT 1
- upgrade undici to latest version HOT 1
- require speedup HOT 2
- keepalive-timeout not work on undici HOT 1
- retry on socket error
- res 对象挂载下 req 相关信息? HOT 1
- When using version 3.x, if an error occurs in writeStream, no error will be thrown HOT 1
- 3.x的nestedQuerystring参数去掉了,我使用2.x的时候使用了这个参数,现在去掉后参数传递不到后端,请问如何升级 HOT 4
- What kind of cookie support is there? HOT 2
- Return type of `request` function is `any` HOT 5
- how to config connecttimeout of err UND_ERR_CONNECT_TIMEOUT HOT 2
- HTTP2 HOT 1
- eol Node.js 16 and use undici@6
- Basic auth is not working
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 urllib.