From 7f4de3522eff592acb55299fe0c270a094d459a8 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 15:46:28 +0800
Subject: [PATCH 001/125] =?UTF-8?q?=E4=BD=BF=E7=94=A8typescript=E5=86=99?=
=?UTF-8?q?=E4=B8=AA=E5=A4=9A=E8=AF=AD=E8=A8=80http=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
.prettierrc.json | 1 +
LICENSE | 693 +++++++++++++++++++++++++++++++++-
README.md | 113 +++---
lib/index.js | 87 -----
lib/index.ts | 49 +++
package.json | 67 ++--
test/common.js | 60 ++-
test/test-early-disconnect.js | 45 ++-
test/test-normal.js | 100 +++--
test/test.js | 9 +-
tsconfig.json | 27 ++
yarn.lock | 173 +++++++++
13 files changed, 1139 insertions(+), 286 deletions(-)
create mode 100644 .gitignore
create mode 100644 .prettierrc.json
delete mode 100644 lib/index.js
create mode 100644 lib/index.ts
create mode 100644 tsconfig.json
create mode 100644 yarn.lock
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.prettierrc.json b/.prettierrc.json
new file mode 100644
index 0000000..a35f439
--- /dev/null
+++ b/.prettierrc.json
@@ -0,0 +1 @@
+{ "tabWidth": 4, "arrowParens": "always" }
diff --git a/LICENSE b/LICENSE
index 3d983a8..e72bfdd 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,19 +1,674 @@
-Copyright 2014 Brian White. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal in the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
\ No newline at end of file
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
\ No newline at end of file
diff --git a/README.md b/README.md
index 8d1ac54..d77b935 100644
--- a/README.md
+++ b/README.md
@@ -1,81 +1,76 @@
-Description
-===========
+# Description
-A module for serving http and https connections over the same port.
+Serve http and https and spdy and http2 connections over the same port with node.js
-Forked from the original [`httpolyglot`](https://github.com/mscdex/httpolyglot) to fix various issues required for [HTTP Toolkit](https://httptoolkit.tech), including:
+# Requirements
-* Fixing `tlsClientError`: https://github.com/mscdex/httpolyglot/pull/11.
-* Exposing the lost bytes from https://github.com/mscdex/httpolyglot/issues/13 on the socket, as `__httpPeekedData`.
-* Dropping support for old versions of Node (and thereby simplifying the code somewhat)
+- [node.js](http://nodejs.org/) -- v8.0.0 or newer
-Requirements
-============
+# Install
-* [node.js](http://nodejs.org/) -- v8.0.0 or newer
+ npm install @masx200/http-https-spdy-http2-polyglot
+# Examples
-Install
-============
-
- npm install @httptoolkit/httpolyglot
-
-
-Examples
-========
-
-* Simple usage:
+- Simple usage:
```javascript
-const httpolyglot = require('@httptoolkit/httpolyglot');
-const fs = require('fs');
-
-httpolyglot.createServer({
- key: fs.readFileSync('server.key'),
- cert: fs.readFileSync('server.crt')
-}, function(req, res) {
- res.writeHead(200, { 'Content-Type': 'text/plain' });
- res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!');
-}).listen(9000, 'localhost', function() {
- console.log('httpolyglot server listening on port 9000');
- // visit http://localhost:9000 and https://localhost:9000 in your browser ...
-});
+const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
+const fs = require("fs");
+
+httpolyglot
+ .createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end((req.socket.encrypted ? "HTTPS" : "HTTP") + " Connection!");
+ }
+ )
+ .listen(9000, "localhost", function () {
+ console.log("httpolyglot server listening on port 9000");
+ });
```
-* Simple redirect of all http connections to https:
+- Simple redirect of all http connections to https:
```javascript
-const httpolyglot = require('@httptoolkit/httpolyglot');
-const fs = require('fs');
-
-httpolyglot.createServer({
- key: fs.readFileSync('server.key'),
- cert: fs.readFileSync('server.crt')
-}, function(req, res) {
- if (!req.socket.encrypted) {
- res.writeHead(301, { 'Location': 'https://localhost:9000' });
- return res.end();
- }
- res.writeHead(200, { 'Content-Type': 'text/plain' });
- res.end('Welcome, HTTPS user!');
-}).listen(9000, 'localhost', function() {
- console.log('httpolyglot server listening on port 9000');
- // visit http://localhost:9000 and https://localhost:9000 in your browser ...
-});
+const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
+const fs = require("fs");
+
+httpolyglot
+ .createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ if (!req.socket.encrypted) {
+ res.writeHead(301, { Location: "https://localhost:9000" });
+ return res.end();
+ } else {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
+ }
+ }
+ )
+ .listen(9000, "localhost", function () {
+ console.log("httpolyglot server listening on port 9000");
+ });
```
+# API
-API
-===
+## Exports
-Exports
--------
+- **Server** - A class similar to https.Server (except instances have `setTimeout()` from http.Server).
-* **Server** - A class similar to https.Server (except instances have `setTimeout()` from http.Server).
+- **createServer**(< _object_ >tlsConfig[, < _function_ >requestListener]) - _Server_ - Creates and returns a new Server instance.
-* **createServer**(< _object_ >tlsConfig[, < _function_ >requestListener]) - _Server_ - Creates and returns a new Server instance.
+# How it Works
-How it Works
-============
+https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
TLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See [this comment](https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155) for more information.
diff --git a/lib/index.js b/lib/index.js
deleted file mode 100644
index f794c4b..0000000
--- a/lib/index.js
+++ /dev/null
@@ -1,87 +0,0 @@
-const http = require('http');
-const https = require('https');
-const inherits = require('util').inherits;
-const httpSocketHandler = http._connectionListener;
-
-function Server(tlsconfig, requestListener) {
- if (!(this instanceof Server)) return new Server(tlsconfig, requestListener);
-
- if (typeof tlsconfig === 'function') {
- requestListener = tlsconfig;
- tlsconfig = undefined;
- }
-
- if (typeof tlsconfig === 'object') {
- this.removeAllListeners('connection');
-
- https.Server.call(this, tlsconfig, requestListener);
-
- // capture https socket handler, it's not exported like http's socket
- // handler
- const connev = this._events.connection;
- if (typeof connev === 'function') {
- this._tlsHandler = connev;
- } else {
- this._tlsHandler = connev[connev.length - 1];
- }
- this.removeListener('connection', this._tlsHandler);
-
- this._connListener = connectionListener;
- this.on('connection', connectionListener);
-
- // copy from http.Server
- this.timeout = 2 * 60 * 1000;
- this.allowHalfOpen = true;
- this.httpAllowHalfOpen = false;
- } else {
- http.Server.call(this, requestListener);
- }
-}
-inherits(Server, https.Server);
-
-Server.prototype.setTimeout = function (msecs, callback) {
- this.timeout = msecs;
- if (callback) this.on('timeout', callback);
-};
-
-Server.prototype.__httpSocketHandler = httpSocketHandler;
-
-function onError(err) {}
-
-const connectionListener = function (socket) {
- const data = socket.read(1);
-
- if (data === null) {
- socket.removeListener('error', onError);
- socket.on('error', onError);
-
- socket.once('readable', () => {
- this._connListener(socket);
- });
- } else {
- socket.removeListener('error', onError);
-
- const firstByte = data[0];
- socket.unshift(data);
- if (firstByte < 32 || firstByte >= 127) {
- // tls/ssl
- // TLS sockets don't allow half open
- socket.allowHalfOpen = false;
- this._tlsHandler(socket);
- } else {
- // The above unshift isn't always sufficient to invisibly replace the
- // read data. The rawPacket property on errors in the clientError event
- // specifically is missing this data - this prop makes it available.
- // Bit of a hacky fix, but sufficient to allow for manual workarounds.
- socket.__httpPeekedData = data;
-
- this.__httpSocketHandler(socket);
- }
- }
-};
-
-exports.Server = Server;
-
-exports.createServer = function (tlsconfig, requestListener) {
- return new Server(tlsconfig, requestListener);
-};
diff --git a/lib/index.ts b/lib/index.ts
new file mode 100644
index 0000000..b33b3e4
--- /dev/null
+++ b/lib/index.ts
@@ -0,0 +1,49 @@
+import http from "http";
+import net from "net";
+import spdy from "spdy";
+import events from "events";
+import https from "https";
+
+type ServerOptions = http.ServerOptions & https.ServerOptions;
+class Server extends net.Server {
+ constructor(config: ServerOptions, requestListener: http.RequestListener) {
+ super();
+ const serverhttp = http.createServer(config, requestListener);
+ const serverhttps = spdy.createServer(config, requestListener);
+ if (typeof config === "object") {
+ events.EventEmitter.prototype.removeAllListeners.call(
+ this,
+ "connection"
+ );
+ const connectionListener = function (socket: net.Socket) {
+ socket.on("error", function onError() {});
+ socket.once("data", (data) => {
+ socket.pause();
+
+ const firstByte = data[0];
+ socket.unshift(data);
+ if (firstByte === 22) {
+ serverhttps.emit("connection", socket);
+ } else if (32 < firstByte && firstByte < 127) {
+ serverhttp.emit("connection", socket);
+ } else {
+ return;
+ }
+
+ socket.resume();
+ });
+ };
+ events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
+ } else {
+ throw new Error("options are required!");
+ }
+ }
+}
+
+function createServer(
+ config: ServerOptions,
+ requestListener: http.RequestListener
+) {
+ return new Server(config, requestListener);
+}
+export { createServer, Server };
diff --git a/package.json b/package.json
index fe38f16..8aaee99 100644
--- a/package.json
+++ b/package.json
@@ -1,29 +1,42 @@
{
- "name": "@httptoolkit/httpolyglot",
- "version": "0.2.0",
- "author": "Tim Perry ",
- "description": "Serve http and https connections over the same port with node.js",
- "main": "./lib/index.js",
- "scripts": {
- "test": "node test/test.js"
- },
- "engines": {
- "node": ">=8.0.0"
- },
- "keywords": [
- "http",
- "https",
- "multiplex",
- "polyglot"
- ],
- "licenses": [
- {
- "type": "MIT",
- "url": "http://github.com/httptoolkit/httpolyglot/raw/master/LICENSE"
- }
- ],
- "repository": {
- "type": "git",
- "url": "http://github.com/httptoolkit/httpolyglot.git"
- }
+ "type": "module",
+ "types": "./lib/index.d.ts",
+ "name": "@masx200/http-https-spdy-http2-polyglot",
+ "version": "1.0.0",
+ "main": "./lib/index.js",
+ "scripts": {
+ "build": "tsc",
+ "test": "node test/test.js",
+ "prettier": "prettier --write *.js *.md *.json ./**/*.js */**.ts"
+ },
+ "engines": {
+ "node": ">=8.0.0"
+ },
+ "peerDependencies": {
+ "spdy": "^4.0.2"
+ },
+ "keywords": [
+ "http",
+ "https",
+ "multiplex",
+ "polyglot"
+ ],
+ "dependencies": {
+ "@types/node": "^13.13.0",
+ "@types/spdy": "^3.4.4"
+ },
+ "devDependencies": {
+ "prettier": "^2.0.4"
+ },
+ "license": "ISC",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/masx200/http-https-spdy-http2-polyglot.git"
+ },
+ "author": "masx200 <34191203+masx200@users.noreply.github.com>",
+ "bugs": {
+ "url": "https://github.com/masx200/http-https-spdy-http2-polyglot/issues"
+ },
+ "homepage": "https://github.com/masx200/http-https-spdy-http2-polyglot#readme",
+ "description": "Serve http and https and spdy and http2 connections over the same port with node.js"
}
diff --git a/test/common.js b/test/common.js
index 3c579c0..14db748 100644
--- a/test/common.js
+++ b/test/common.js
@@ -1,43 +1,41 @@
exports.mustCall = mustCall;
function mustCall(fn, expected) {
- if (typeof expected !== 'number')
- expected = 1;
+ if (typeof expected !== "number") expected = 1;
- var context = {
- expected: expected,
- actual: 0,
- stack: (new Error()).stack,
- name: fn.name || ''
- };
+ var context = {
+ expected: expected,
+ actual: 0,
+ stack: new Error().stack,
+ name: fn.name || "",
+ };
- // add the exit listener only once to avoid listener leak warnings
- if (mustCall.checks.length === 0)
- process.on('exit', mustCall.runChecks);
+ // add the exit listener only once to avoid listener leak warnings
+ if (mustCall.checks.length === 0) process.on("exit", mustCall.runChecks);
- mustCall.checks.push(context);
+ mustCall.checks.push(context);
- return function() {
- context.actual++;
- return fn.apply(this, arguments);
- };
+ return function () {
+ context.actual++;
+ return fn.apply(this, arguments);
+ };
}
mustCall.checks = [];
-mustCall.runChecks = function(exitCode) {
- if (exitCode !== 0)
- return;
+mustCall.runChecks = function (exitCode) {
+ if (exitCode !== 0) return;
- var failed = mustCall.checks.filter(function(context) {
- return context.actual !== context.expected;
- });
+ var failed = mustCall.checks.filter(function (context) {
+ return context.actual !== context.expected;
+ });
- failed.forEach(function(context) {
- console.log('Mismatched %s function calls. Expected %d, actual %d.',
- context.name,
- context.expected,
- context.actual);
- console.log(context.stack.split('\n').slice(2).join('\n'));
- });
+ failed.forEach(function (context) {
+ console.log(
+ "Mismatched %s function calls. Expected %d, actual %d.",
+ context.name,
+ context.expected,
+ context.actual
+ );
+ console.log(context.stack.split("\n").slice(2).join("\n"));
+ });
- if (failed.length)
- process.exit(1);
+ if (failed.length) process.exit(1);
};
diff --git a/test/test-early-disconnect.js b/test/test-early-disconnect.js
index 7c1dd87..3a2f849 100755
--- a/test/test-early-disconnect.js
+++ b/test/test-early-disconnect.js
@@ -1,21 +1,30 @@
-var fs = require('fs');
-var exec = require('child_process').exec;
-var assert = require('assert');
+var fs = require("fs");
+var exec = require("child_process").exec;
+var assert = require("assert");
-var common = require(__dirname + '/common');
-var httpolyglot = require(__dirname + '/../lib/index');
+var common = require(__dirname + "/common");
+var httpolyglot = require(__dirname + "/../lib/index");
-var srv = httpolyglot.createServer({
- key: fs.readFileSync(__dirname + '/fixtures/server.key'),
- cert: fs.readFileSync(__dirname + '/fixtures/server.crt')
-}, function(req, res) {
- assert(false, 'Request handler should not be called');
-});
-srv.listen(0, '127.0.0.1', common.mustCall(function() {
- var port = this.address().port;
+var srv = httpolyglot.createServer(
+ {
+ key: fs.readFileSync(__dirname + "/fixtures/server.key"),
+ cert: fs.readFileSync(__dirname + "/fixtures/server.crt"),
+ },
+ function (req, res) {
+ assert(false, "Request handler should not be called");
+ }
+);
+srv.listen(
+ 0,
+ "127.0.0.1",
+ common.mustCall(function () {
+ var port = this.address().port;
- exec('nmap 127.0.0.1 -p' + port,
- common.mustCall(function(err, stdout, stderr) {
- srv.close();
- }));
-}));
+ exec(
+ "nmap 127.0.0.1 -p" + port,
+ common.mustCall(function (err, stdout, stderr) {
+ srv.close();
+ })
+ );
+ })
+);
diff --git a/test/test-normal.js b/test/test-normal.js
index d3c96ac..67bc987 100755
--- a/test/test-normal.js
+++ b/test/test-normal.js
@@ -1,45 +1,63 @@
-var fs = require('fs');
-var http = require('http');
-var https = require('https');
-var assert = require('assert');
+var fs = require("fs");
+var http = require("http");
+var https = require("https");
+var assert = require("assert");
-var common = require(__dirname + '/common');
-var httpolyglot = require(__dirname + '/../lib/index');
+var common = require(__dirname + "/common");
+var httpolyglot = require(__dirname + "/../lib/index");
-var srv = httpolyglot.createServer({
- key: fs.readFileSync(__dirname + '/fixtures/server.key'),
- cert: fs.readFileSync(__dirname + '/fixtures/server.crt')
-}, common.mustCall(function(req, res) {
- this.count || (this.count = 0);
- res.end(req.socket.encrypted ? 'https' : 'http');
- if (++this.count === 2)
- this.close();
-}, 2));
-srv.listen(0, '127.0.0.1', common.mustCall(function() {
- var port = this.address().port;
+var srv = httpolyglot.createServer(
+ {
+ key: fs.readFileSync(__dirname + "/fixtures/server.key"),
+ cert: fs.readFileSync(__dirname + "/fixtures/server.crt"),
+ },
+ common.mustCall(function (req, res) {
+ this.count || (this.count = 0);
+ res.end(req.socket.encrypted ? "https" : "http");
+ if (++this.count === 2) this.close();
+ }, 2)
+);
+srv.listen(
+ 0,
+ "127.0.0.1",
+ common.mustCall(function () {
+ var port = this.address().port;
- http.get({
- host: '127.0.0.1',
- port: port
- }, common.mustCall(function(res) {
- var body = '';
- res.on('data', function(data) {
- body += data;
- }).on('end', common.mustCall(function() {
- assert.strictEqual(body, 'http');
- }));
- }));
+ http.get(
+ {
+ host: "127.0.0.1",
+ port: port,
+ },
+ common.mustCall(function (res) {
+ var body = "";
+ res.on("data", function (data) {
+ body += data;
+ }).on(
+ "end",
+ common.mustCall(function () {
+ assert.strictEqual(body, "http");
+ })
+ );
+ })
+ );
- https.get({
- host: '127.0.0.1',
- port: port,
- rejectUnauthorized: false
- }, common.mustCall(function(res) {
- var body = '';
- res.on('data', function(data) {
- body += data;
- }).on('end', common.mustCall(function() {
- assert.strictEqual(body, 'https');
- }));
- }));
-}));
+ https.get(
+ {
+ host: "127.0.0.1",
+ port: port,
+ rejectUnauthorized: false,
+ },
+ common.mustCall(function (res) {
+ var body = "";
+ res.on("data", function (data) {
+ body += data;
+ }).on(
+ "end",
+ common.mustCall(function () {
+ assert.strictEqual(body, "https");
+ })
+ );
+ })
+ );
+ })
+);
diff --git a/test/test.js b/test/test.js
index b2b0dba..23c9fc3 100755
--- a/test/test.js
+++ b/test/test.js
@@ -1,4 +1,5 @@
-require('fs').readdirSync(__dirname).forEach(function(f) {
- if (f.substr(0, 5) === 'test-')
- require('./' + f);
-});
+require("fs")
+ .readdirSync(__dirname)
+ .forEach(function (f) {
+ if (f.substr(0, 5) === "test-") require("./" + f);
+ });
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 0000000..f15fb65
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,27 @@
+{
+ "include": ["*/**.ts"],
+ "compilerOptions": {
+ "pretty": true,
+ "removeComments": true,
+ "moduleResolution": "node",
+ "resolveJsonModule": false,
+ "declaration": true,
+ "allowJs": true,
+ "checkJs": false,
+ "charset": "utf-8",
+ "strict": true,
+ "target": "ESNEXT",
+ "module": "ESNEXT",
+ "importHelpers": true,
+ "noImplicitAny": true,
+ "strictNullChecks": true,
+ "noImplicitThis": true,
+ "alwaysStrict": true,
+ "noUnusedLocals": true,
+ "noImplicitReturns": true,
+ "noFallthroughCasesInSwitch": true,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "forceConsistentCasingInFileNames": true
+ }
+}
diff --git a/yarn.lock b/yarn.lock
new file mode 100644
index 0000000..db6989b
--- /dev/null
+++ b/yarn.lock
@@ -0,0 +1,173 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"@types/node@*", "@types/node@^13.13.0":
+ version "13.13.0"
+ resolved "https://registry.npmjs.org/@types/node/-/node-13.13.0.tgz#30d2d09f623fe32cde9cb582c7a6eda2788ce4a8"
+ integrity sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==
+
+"@types/spdy@^3.4.4":
+ version "3.4.4"
+ resolved "https://registry.npmjs.org/@types/spdy/-/spdy-3.4.4.tgz#3282fd4ad8c4603aa49f7017dd520a08a345b2bc"
+ integrity sha512-N9LBlbVRRYq6HgYpPkqQc3a9HJ/iEtVZToW6xlTtJiMhmRJ7jJdV7TaZQJw/Ve/1ePUsQiCTDc4JMuzzag94GA==
+ dependencies:
+ "@types/node" "*"
+
+core-util-is@~1.0.0:
+ version "1.0.2"
+ resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
+ integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
+
+debug@^4.1.0:
+ version "4.1.1"
+ resolved "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
+ integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
+ dependencies:
+ ms "^2.1.1"
+
+detect-node@^2.0.4:
+ version "2.0.4"
+ resolved "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz#014ee8f8f669c5c58023da64b8179c083a28c46c"
+ integrity sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==
+
+handle-thing@^2.0.0:
+ version "2.0.1"
+ resolved "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
+ integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg==
+
+hpack.js@^2.1.6:
+ version "2.1.6"
+ resolved "https://registry.npmjs.org/hpack.js/-/hpack.js-2.1.6.tgz#87774c0949e513f42e84575b3c45681fade2a0b2"
+ integrity sha1-h3dMCUnlE/QuhFdbPEVoH63ioLI=
+ dependencies:
+ inherits "^2.0.1"
+ obuf "^1.0.0"
+ readable-stream "^2.0.1"
+ wbuf "^1.1.0"
+
+http-deceiver@^1.2.7:
+ version "1.2.7"
+ resolved "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz#fa7168944ab9a519d337cb0bec7284dc3e723d87"
+ integrity sha1-+nFolEq5pRnTN8sL7HKE3D5yPYc=
+
+inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3:
+ version "2.0.4"
+ resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
+ integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
+
+isarray@~1.0.0:
+ version "1.0.0"
+ resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
+ integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
+
+minimalistic-assert@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
+ integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
+
+ms@^2.1.1:
+ version "2.1.2"
+ resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
+ integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
+
+obuf@^1.0.0, obuf@^1.1.2:
+ version "1.1.2"
+ resolved "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
+ integrity sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==
+
+prettier@^2.0.4:
+ version "2.0.4"
+ resolved "https://registry.npmjs.org/prettier/-/prettier-2.0.4.tgz#2d1bae173e355996ee355ec9830a7a1ee05457ef"
+ integrity sha512-SVJIQ51spzFDvh4fIbCLvciiDMCrRhlN3mbZvv/+ycjvmF5E73bKdGfU8QDLNmjYJf+lsGnDBC4UUnvTe5OO0w==
+
+process-nextick-args@~2.0.0:
+ version "2.0.1"
+ resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
+ integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
+
+readable-stream@^2.0.1:
+ version "2.3.7"
+ resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
+ integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
+ dependencies:
+ core-util-is "~1.0.0"
+ inherits "~2.0.3"
+ isarray "~1.0.0"
+ process-nextick-args "~2.0.0"
+ safe-buffer "~5.1.1"
+ string_decoder "~1.1.1"
+ util-deprecate "~1.0.1"
+
+readable-stream@^3.0.6:
+ version "3.6.0"
+ resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
+ integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
+ dependencies:
+ inherits "^2.0.3"
+ string_decoder "^1.1.1"
+ util-deprecate "^1.0.1"
+
+safe-buffer@~5.1.0, safe-buffer@~5.1.1:
+ version "5.1.2"
+ resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
+ integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
+
+safe-buffer@~5.2.0:
+ version "5.2.0"
+ resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
+ integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==
+
+select-hose@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
+ integrity sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo=
+
+spdy-transport@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.npmjs.org/spdy-transport/-/spdy-transport-3.0.0.tgz#00d4863a6400ad75df93361a1608605e5dcdcf31"
+ integrity sha512-hsLVFE5SjA6TCisWeJXFKniGGOpBgMLmerfO2aCyCU5s7nJ/rpAepqmFifv/GCbSbueEeAJJnmSQ2rKC/g8Fcw==
+ dependencies:
+ debug "^4.1.0"
+ detect-node "^2.0.4"
+ hpack.js "^2.1.6"
+ obuf "^1.1.2"
+ readable-stream "^3.0.6"
+ wbuf "^1.7.3"
+
+spdy@^4.0.2:
+ version "4.0.2"
+ resolved "https://registry.npmjs.org/spdy/-/spdy-4.0.2.tgz#b74f466203a3eda452c02492b91fb9e84a27677b"
+ integrity sha512-r46gZQZQV+Kl9oItvl1JZZqJKGr+oEkB08A6BzkiR7593/7IbtuncXHd2YoYeTsG4157ZssMu9KYvUHLcjcDoA==
+ dependencies:
+ debug "^4.1.0"
+ handle-thing "^2.0.0"
+ http-deceiver "^1.2.7"
+ select-hose "^2.0.0"
+ spdy-transport "^3.0.0"
+
+string_decoder@^1.1.1:
+ version "1.3.0"
+ resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
+ integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
+ dependencies:
+ safe-buffer "~5.2.0"
+
+string_decoder@~1.1.1:
+ version "1.1.1"
+ resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
+ integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
+ dependencies:
+ safe-buffer "~5.1.0"
+
+util-deprecate@^1.0.1, util-deprecate@~1.0.1:
+ version "1.0.2"
+ resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
+ integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
+
+wbuf@^1.1.0, wbuf@^1.7.3:
+ version "1.7.3"
+ resolved "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz#c1d8d149316d3ea852848895cb6a0bfe887b87df"
+ integrity sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==
+ dependencies:
+ minimalistic-assert "^1.0.0"
From c0ef27650b16a5d093c04ec7936fe5ecbab28d83 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 15:50:26 +0800
Subject: [PATCH 002/125] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d77b935..aa14342 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ httpolyglot
## Exports
-- **Server** - A class similar to https.Server (except instances have `setTimeout()` from http.Server).
+- **Server** - A class similar to https.Server .
- **createServer**(< _object_ >tlsConfig[, < _function_ >requestListener]) - _Server_ - Creates and returns a new Server instance.
From d2191743ec551f6ba5793785339845da0f80c169 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 15:52:03 +0800
Subject: [PATCH 003/125] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index aa14342..f4c0978 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,9 @@ Serve http and https and spdy and http2 connections over the same port with node
# Install
- npm install @masx200/http-https-spdy-http2-polyglot
+```shell
+yarn add spdy @masx200/http-https-spdy-http2-polyglot
+```
# Examples
From 36823383a013c907d2a76f228b149b5d254c10ae Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 15:56:09 +0800
Subject: [PATCH 004/125] Update README.md
---
README.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index f4c0978..80f7a54 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ httpolyglot
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
const fs = require("fs");
-
+const port = 9000;
httpolyglot
.createServer(
{
@@ -58,8 +58,8 @@ httpolyglot
}
}
)
- .listen(9000, "localhost", function () {
- console.log("httpolyglot server listening on port 9000");
+ .listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
});
```
@@ -69,7 +69,7 @@ httpolyglot
- **Server** - A class similar to https.Server .
-- **createServer**(< _object_ >tlsConfig[, < _function_ >requestListener]) - _Server_ - Creates and returns a new Server instance.
+- **createServer** - Creates and returns a new Server instance.
# How it Works
From 8c92594feeed3348b1af7b9b159ba2e0216c2a5b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 15:56:55 +0800
Subject: [PATCH 005/125] Update README.md
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 80f7a54..b545128 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ yarn add spdy @masx200/http-https-spdy-http2-polyglot
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
const fs = require("fs");
-
+const port = 9000;
httpolyglot
.createServer(
{
@@ -31,8 +31,8 @@ httpolyglot
res.end((req.socket.encrypted ? "HTTPS" : "HTTP") + " Connection!");
}
)
- .listen(9000, "localhost", function () {
- console.log("httpolyglot server listening on port 9000");
+ .listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
});
```
From b69eea29aac2d5fceaca86781df7e6f9e86385dd Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:01:33 +0800
Subject: [PATCH 006/125] Update README.md
---
README.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b545128..ef76727 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,11 @@ httpolyglot
},
function (req, res) {
if (!req.socket.encrypted) {
- res.writeHead(301, { Location: "https://localhost:9000" });
+ const host = req.headers["host"];
+ const originurl = req.url;
+ const tourl = new URL(req.url, "https://" + host);
+ tourl.port = String(port);
+ res.writeHead(301, { Location: tourl.href });
return res.end();
} else {
res.writeHead(200, { "Content-Type": "text/plain" });
From bcf431de99fdfa52781cde266ee8d1dd3386ac4a Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:34:40 +0800
Subject: [PATCH 007/125] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 +--
lib/index.d.ts | 10 ++++++
lib/index.js | 41 ++++++++++++++++++++++
lib/index.ts | 1 +
test/common.js | 41 ----------------------
test/one.d.ts | 1 +
test/one.js | 12 +++++++
test/one.ts | 16 +++++++++
test/{fixtures => }/server.crt | 0
test/{fixtures => }/server.key | 0
test/test-early-disconnect.js | 30 ----------------
test/test-normal.js | 63 ----------------------------------
test/test.js | 7 ++--
test/two.d.ts | 1 +
test/two.js | 22 ++++++++++++
test/two.ts | 24 +++++++++++++
tsconfig.json | 2 ++
17 files changed, 134 insertions(+), 141 deletions(-)
create mode 100644 lib/index.d.ts
create mode 100644 lib/index.js
delete mode 100644 test/common.js
create mode 100644 test/one.d.ts
create mode 100644 test/one.js
create mode 100644 test/one.ts
rename test/{fixtures => }/server.crt (100%)
rename test/{fixtures => }/server.key (100%)
delete mode 100755 test/test-early-disconnect.js
delete mode 100755 test/test-normal.js
create mode 100644 test/two.d.ts
create mode 100644 test/two.js
create mode 100644 test/two.ts
diff --git a/README.md b/README.md
index ef76727..974be62 100644
--- a/README.md
+++ b/README.md
@@ -51,8 +51,8 @@ httpolyglot
function (req, res) {
if (!req.socket.encrypted) {
const host = req.headers["host"];
- const originurl = req.url;
- const tourl = new URL(req.url, "https://" + host);
+ const originurl = req.url || "";
+ const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
res.writeHead(301, { Location: tourl.href });
return res.end();
diff --git a/lib/index.d.ts b/lib/index.d.ts
new file mode 100644
index 0000000..8d8a7a2
--- /dev/null
+++ b/lib/index.d.ts
@@ -0,0 +1,10 @@
+///
+import http from "http";
+import net from "net";
+import https from "https";
+declare type ServerOptions = http.ServerOptions & https.ServerOptions;
+declare class Server extends net.Server {
+ constructor(config: ServerOptions, requestListener: http.RequestListener);
+}
+declare function createServer(config: ServerOptions, requestListener: http.RequestListener): Server;
+export { createServer, Server };
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 0000000..9e5ecf7
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1,41 @@
+import http from "http";
+import net from "net";
+import http2 from "http2";
+import events from "events";
+class Server extends net.Server {
+ constructor(config, requestListener) {
+ super();
+ const serverhttp = http.createServer(config, requestListener);
+ const serverhttps = http2.createSecureServer(config, requestListener);
+ if (typeof config === "object") {
+ events.EventEmitter.prototype.removeAllListeners.call(this, "connection");
+ const connectionListener = function (socket) {
+ socket.on("error", function onError() { });
+ socket.once("data", (data) => {
+ socket.pause();
+ const firstByte = data[0];
+ socket.unshift(data);
+ if (firstByte === 22) {
+ serverhttps.emit("connection", socket);
+ }
+ else if (32 < firstByte && firstByte < 127) {
+ serverhttp.emit("connection", socket);
+ }
+ else {
+ socket.end();
+ return;
+ }
+ socket.resume();
+ });
+ };
+ events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
+ }
+ else {
+ throw new Error("options are required!");
+ }
+ }
+}
+function createServer(config, requestListener) {
+ return new Server(config, requestListener);
+}
+export { createServer, Server };
diff --git a/lib/index.ts b/lib/index.ts
index b33b3e4..58dfef5 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -27,6 +27,7 @@ class Server extends net.Server {
} else if (32 < firstByte && firstByte < 127) {
serverhttp.emit("connection", socket);
} else {
+ socket.end();
return;
}
diff --git a/test/common.js b/test/common.js
deleted file mode 100644
index 14db748..0000000
--- a/test/common.js
+++ /dev/null
@@ -1,41 +0,0 @@
-exports.mustCall = mustCall;
-function mustCall(fn, expected) {
- if (typeof expected !== "number") expected = 1;
-
- var context = {
- expected: expected,
- actual: 0,
- stack: new Error().stack,
- name: fn.name || "",
- };
-
- // add the exit listener only once to avoid listener leak warnings
- if (mustCall.checks.length === 0) process.on("exit", mustCall.runChecks);
-
- mustCall.checks.push(context);
-
- return function () {
- context.actual++;
- return fn.apply(this, arguments);
- };
-}
-mustCall.checks = [];
-mustCall.runChecks = function (exitCode) {
- if (exitCode !== 0) return;
-
- var failed = mustCall.checks.filter(function (context) {
- return context.actual !== context.expected;
- });
-
- failed.forEach(function (context) {
- console.log(
- "Mismatched %s function calls. Expected %d, actual %d.",
- context.name,
- context.expected,
- context.actual
- );
- console.log(context.stack.split("\n").slice(2).join("\n"));
- });
-
- if (failed.length) process.exit(1);
-};
diff --git a/test/one.d.ts b/test/one.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/test/one.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/test/one.js b/test/one.js
new file mode 100644
index 0000000..fa4ea8c
--- /dev/null
+++ b/test/one.js
@@ -0,0 +1,12 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 9000;
+createServer({
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+}, function (req, res) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
+}).listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
diff --git a/test/one.ts b/test/one.ts
new file mode 100644
index 0000000..46142de
--- /dev/null
+++ b/test/one.ts
@@ -0,0 +1,16 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 9000;
+
+createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
+ }
+).listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
diff --git a/test/fixtures/server.crt b/test/server.crt
similarity index 100%
rename from test/fixtures/server.crt
rename to test/server.crt
diff --git a/test/fixtures/server.key b/test/server.key
similarity index 100%
rename from test/fixtures/server.key
rename to test/server.key
diff --git a/test/test-early-disconnect.js b/test/test-early-disconnect.js
deleted file mode 100755
index 3a2f849..0000000
--- a/test/test-early-disconnect.js
+++ /dev/null
@@ -1,30 +0,0 @@
-var fs = require("fs");
-var exec = require("child_process").exec;
-var assert = require("assert");
-
-var common = require(__dirname + "/common");
-var httpolyglot = require(__dirname + "/../lib/index");
-
-var srv = httpolyglot.createServer(
- {
- key: fs.readFileSync(__dirname + "/fixtures/server.key"),
- cert: fs.readFileSync(__dirname + "/fixtures/server.crt"),
- },
- function (req, res) {
- assert(false, "Request handler should not be called");
- }
-);
-srv.listen(
- 0,
- "127.0.0.1",
- common.mustCall(function () {
- var port = this.address().port;
-
- exec(
- "nmap 127.0.0.1 -p" + port,
- common.mustCall(function (err, stdout, stderr) {
- srv.close();
- })
- );
- })
-);
diff --git a/test/test-normal.js b/test/test-normal.js
deleted file mode 100755
index 67bc987..0000000
--- a/test/test-normal.js
+++ /dev/null
@@ -1,63 +0,0 @@
-var fs = require("fs");
-var http = require("http");
-var https = require("https");
-var assert = require("assert");
-
-var common = require(__dirname + "/common");
-var httpolyglot = require(__dirname + "/../lib/index");
-
-var srv = httpolyglot.createServer(
- {
- key: fs.readFileSync(__dirname + "/fixtures/server.key"),
- cert: fs.readFileSync(__dirname + "/fixtures/server.crt"),
- },
- common.mustCall(function (req, res) {
- this.count || (this.count = 0);
- res.end(req.socket.encrypted ? "https" : "http");
- if (++this.count === 2) this.close();
- }, 2)
-);
-srv.listen(
- 0,
- "127.0.0.1",
- common.mustCall(function () {
- var port = this.address().port;
-
- http.get(
- {
- host: "127.0.0.1",
- port: port,
- },
- common.mustCall(function (res) {
- var body = "";
- res.on("data", function (data) {
- body += data;
- }).on(
- "end",
- common.mustCall(function () {
- assert.strictEqual(body, "http");
- })
- );
- })
- );
-
- https.get(
- {
- host: "127.0.0.1",
- port: port,
- rejectUnauthorized: false,
- },
- common.mustCall(function (res) {
- var body = "";
- res.on("data", function (data) {
- body += data;
- }).on(
- "end",
- common.mustCall(function () {
- assert.strictEqual(body, "https");
- })
- );
- })
- );
- })
-);
diff --git a/test/test.js b/test/test.js
index 23c9fc3..6203bcd 100755
--- a/test/test.js
+++ b/test/test.js
@@ -1,5 +1,2 @@
-require("fs")
- .readdirSync(__dirname)
- .forEach(function (f) {
- if (f.substr(0, 5) === "test-") require("./" + f);
- });
+import "./one.js";
+import "./two.js";
diff --git a/test/two.d.ts b/test/two.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/test/two.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/test/two.js b/test/two.js
new file mode 100644
index 0000000..3a20d07
--- /dev/null
+++ b/test/two.js
@@ -0,0 +1,22 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 9001;
+createServer({
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+}, function (req, res) {
+ if (!req.socket) {
+ const host = req.headers["host"];
+ const originurl = req.url || "";
+ const tourl = new URL(originurl, "https://" + host);
+ tourl.port = String(port);
+ res.writeHead(302, { Location: tourl.href });
+ return res.end();
+ }
+ else {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
+ }
+}).listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
diff --git a/test/two.ts b/test/two.ts
new file mode 100644
index 0000000..4afdb15
--- /dev/null
+++ b/test/two.ts
@@ -0,0 +1,24 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 9001;
+createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ if (!req.socket) {
+ const host = req.headers["host"];
+ const originurl = req.url || "";
+ const tourl = new URL(originurl, "https://" + host);
+ tourl.port = String(port);
+ res.writeHead(302, { Location: tourl.href });
+ return res.end();
+ } else {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
+ }
+ }
+).listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
diff --git a/tsconfig.json b/tsconfig.json
index f15fb65..96c8708 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,6 +1,8 @@
{
"include": ["*/**.ts"],
"compilerOptions": {
+ "baseUrl": ".",
+ "paths": {},
"pretty": true,
"removeComments": true,
"moduleResolution": "node",
From 30f0eb66d0a2c1983b491390e53f8c9457287dce Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:47:49 +0800
Subject: [PATCH 008/125] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 5 ++++-
lib/index.js | 26 +++++++++++++++-----------
lib/index.ts | 7 ++++++-
package.json | 2 +-
test/one.js | 17 ++++++++++-------
test/two.js | 34 ++++++++++++++++++----------------
6 files changed, 54 insertions(+), 37 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 8d8a7a2..0d71b07 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -6,5 +6,8 @@ declare type ServerOptions = http.ServerOptions & https.ServerOptions;
declare class Server extends net.Server {
constructor(config: ServerOptions, requestListener: http.RequestListener);
}
-declare function createServer(config: ServerOptions, requestListener: http.RequestListener): Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener: http.RequestListener
+): Server;
export { createServer, Server };
diff --git a/lib/index.js b/lib/index.js
index 9e5ecf7..0c611a1 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,36 +1,40 @@
import http from "http";
import net from "net";
-import http2 from "http2";
+import spdy from "spdy";
import events from "events";
class Server extends net.Server {
constructor(config, requestListener) {
super();
const serverhttp = http.createServer(config, requestListener);
- const serverhttps = http2.createSecureServer(config, requestListener);
+ const serverhttps = spdy.createServer(config, requestListener);
if (typeof config === "object") {
- events.EventEmitter.prototype.removeAllListeners.call(this, "connection");
+ events.EventEmitter.prototype.removeAllListeners.call(
+ this,
+ "connection"
+ );
const connectionListener = function (socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
socket.once("data", (data) => {
socket.pause();
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
serverhttps.emit("connection", socket);
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
serverhttp.emit("connection", socket);
- }
- else {
+ } else {
socket.end();
return;
}
socket.resume();
});
};
- events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
- }
- else {
+ events.EventEmitter.prototype.on.call(
+ this,
+ "connection",
+ connectionListener
+ );
+ } else {
throw new Error("options are required!");
}
}
diff --git a/lib/index.ts b/lib/index.ts
index 58dfef5..06c66ef 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -22,6 +22,7 @@ class Server extends net.Server {
const firstByte = data[0];
socket.unshift(data);
+
if (firstByte === 22) {
serverhttps.emit("connection", socket);
} else if (32 < firstByte && firstByte < 127) {
@@ -34,7 +35,11 @@ class Server extends net.Server {
socket.resume();
});
};
- events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
+ events.EventEmitter.prototype.on.call(
+ this,
+ "connection",
+ connectionListener
+ );
} else {
throw new Error("options are required!");
}
diff --git a/package.json b/package.json
index 8aaee99..73190c0 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"test": "node test/test.js",
- "prettier": "prettier --write *.js *.md *.json ./**/*.js */**.ts"
+ "prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
"node": ">=8.0.0"
diff --git a/test/one.js b/test/one.js
index fa4ea8c..d04f0ec 100644
--- a/test/one.js
+++ b/test/one.js
@@ -1,12 +1,15 @@
import { createServer } from "../lib/index.js";
import fs from "fs";
const port = 9000;
-createServer({
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
-}, function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
-}).listen(port, "localhost", function () {
+createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
+ }
+).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
});
diff --git a/test/two.js b/test/two.js
index 3a20d07..4afdb15 100644
--- a/test/two.js
+++ b/test/two.js
@@ -1,22 +1,24 @@
import { createServer } from "../lib/index.js";
import fs from "fs";
const port = 9001;
-createServer({
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
-}, function (req, res) {
- if (!req.socket) {
- const host = req.headers["host"];
- const originurl = req.url || "";
- const tourl = new URL(originurl, "https://" + host);
- tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href });
- return res.end();
+createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ if (!req.socket) {
+ const host = req.headers["host"];
+ const originurl = req.url || "";
+ const tourl = new URL(originurl, "https://" + host);
+ tourl.port = String(port);
+ res.writeHead(302, { Location: tourl.href });
+ return res.end();
+ } else {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
+ }
}
- else {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end("Welcome, HTTPS user!");
- }
-}).listen(port, "localhost", function () {
+).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
});
From eafd7f2b90fb4a9c62828ca530ec05ba9abd4363 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:58:02 +0800
Subject: [PATCH 009/125] Update index.ts
---
lib/index.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 06c66ef..40995a5 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,7 +3,7 @@ import net from "net";
import spdy from "spdy";
import events from "events";
import https from "https";
-
+import { inherits } from "util";
type ServerOptions = http.ServerOptions & https.ServerOptions;
class Server extends net.Server {
constructor(config: ServerOptions, requestListener: http.RequestListener) {
@@ -45,7 +45,7 @@ class Server extends net.Server {
}
}
}
-
+inherits(Server, https.Server);
function createServer(
config: ServerOptions,
requestListener: http.RequestListener
From c1b958dbe2f4f0267547c87fe51956b709d51a0c Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 17:01:04 +0800
Subject: [PATCH 010/125] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 3 +++
test/one.js | 5 +++--
test/one.ts | 16 ----------------
test/two.js | 5 +++--
test/two.ts | 24 ------------------------
5 files changed, 9 insertions(+), 44 deletions(-)
delete mode 100644 test/one.ts
delete mode 100644 test/two.ts
diff --git a/lib/index.js b/lib/index.js
index 0c611a1..99a6840 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,6 +2,8 @@ import http from "http";
import net from "net";
import spdy from "spdy";
import events from "events";
+import https from "https";
+import { inherits } from "util";
class Server extends net.Server {
constructor(config, requestListener) {
super();
@@ -39,6 +41,7 @@ class Server extends net.Server {
}
}
}
+inherits(Server, https.Server);
function createServer(config, requestListener) {
return new Server(config, requestListener);
}
diff --git a/test/one.js b/test/one.js
index d04f0ec..9766582 100644
--- a/test/one.js
+++ b/test/one.js
@@ -1,10 +1,11 @@
import { createServer } from "../lib/index.js";
import fs from "fs";
const port = 9000;
+import path from "path";
createServer(
{
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
+ key: fs.readFileSync(path.join(__dirname, "server.key")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
diff --git a/test/one.ts b/test/one.ts
deleted file mode 100644
index 46142de..0000000
--- a/test/one.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { createServer } from "../lib/index.js";
-import fs from "fs";
-const port = 9000;
-
-createServer(
- {
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
- },
- function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
- }
-).listen(port, "localhost", function () {
- console.log("httpolyglot server listening on port " + port);
-});
diff --git a/test/two.js b/test/two.js
index 4afdb15..59f6876 100644
--- a/test/two.js
+++ b/test/two.js
@@ -1,10 +1,11 @@
import { createServer } from "../lib/index.js";
import fs from "fs";
+import path from "path";
const port = 9001;
createServer(
{
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
+ key: fs.readFileSync(path.join(__dirname, "server.key")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
if (!req.socket) {
diff --git a/test/two.ts b/test/two.ts
deleted file mode 100644
index 4afdb15..0000000
--- a/test/two.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { createServer } from "../lib/index.js";
-import fs from "fs";
-const port = 9001;
-createServer(
- {
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
- },
- function (req, res) {
- if (!req.socket) {
- const host = req.headers["host"];
- const originurl = req.url || "";
- const tourl = new URL(originurl, "https://" + host);
- tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href });
- return res.end();
- } else {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end("Welcome, HTTPS user!");
- }
- }
-).listen(port, "localhost", function () {
- console.log("httpolyglot server listening on port " + port);
-});
From eb50c722863465537fe8e0b4c022d9a3a1ce46be Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 17:08:29 +0800
Subject: [PATCH 011/125] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/one.js | 5 +++++
test/two.js | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/test/one.js b/test/one.js
index 9766582..5546d46 100644
--- a/test/one.js
+++ b/test/one.js
@@ -2,6 +2,11 @@ import { createServer } from "../lib/index.js";
import fs from "fs";
const port = 9000;
import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
createServer(
{
key: fs.readFileSync(path.join(__dirname, "server.key")),
diff --git a/test/two.js b/test/two.js
index 59f6876..40f734d 100644
--- a/test/two.js
+++ b/test/two.js
@@ -1,6 +1,11 @@
import { createServer } from "../lib/index.js";
import fs from "fs";
import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
const port = 9001;
createServer(
{
From d4c4f72a4b0d8437cefac1d35ebb60773fc17e7d Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 17:18:46 +0800
Subject: [PATCH 012/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 5 +----
lib/index.js | 24 +++++++++---------------
lib/index.ts | 3 ---
3 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 0d71b07..8d8a7a2 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -6,8 +6,5 @@ declare type ServerOptions = http.ServerOptions & https.ServerOptions;
declare class Server extends net.Server {
constructor(config: ServerOptions, requestListener: http.RequestListener);
}
-declare function createServer(
- config: ServerOptions,
- requestListener: http.RequestListener
-): Server;
+declare function createServer(config: ServerOptions, requestListener: http.RequestListener): Server;
export { createServer, Server };
diff --git a/lib/index.js b/lib/index.js
index 99a6840..a86c909 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -10,33 +10,27 @@ class Server extends net.Server {
const serverhttp = http.createServer(config, requestListener);
const serverhttps = spdy.createServer(config, requestListener);
if (typeof config === "object") {
- events.EventEmitter.prototype.removeAllListeners.call(
- this,
- "connection"
- );
+ events.EventEmitter.prototype.removeAllListeners.call(this, "connection");
const connectionListener = function (socket) {
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
socket.once("data", (data) => {
- socket.pause();
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
serverhttps.emit("connection", socket);
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
serverhttp.emit("connection", socket);
- } else {
+ }
+ else {
socket.end();
return;
}
- socket.resume();
});
};
- events.EventEmitter.prototype.on.call(
- this,
- "connection",
- connectionListener
- );
- } else {
+ events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
+ }
+ else {
throw new Error("options are required!");
}
}
diff --git a/lib/index.ts b/lib/index.ts
index 40995a5..d3e9132 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -27,9 +27,6 @@ class Server extends net.Server {
serverhttps.emit("connection", socket);
} else if (32 < firstByte && firstByte < 127) {
serverhttp.emit("connection", socket);
- } else {
- socket.end();
- return;
}
socket.resume();
From 8c8c4a0d6135d08545987718605eca45baae3bbb Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 17:41:43 +0800
Subject: [PATCH 013/125] Update index.ts
---
lib/index.ts | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index d3e9132..31c60c6 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,11 +3,11 @@ import net from "net";
import spdy from "spdy";
import events from "events";
import https from "https";
-import { inherits } from "util";
-type ServerOptions = http.ServerOptions & https.ServerOptions;
-class Server extends net.Server {
+import tls from "tls";
+type ServerOptions = https.ServerOptions;
+class Server extends tls.Server {
constructor(config: ServerOptions, requestListener: http.RequestListener) {
- super();
+ super(config);
const serverhttp = http.createServer(config, requestListener);
const serverhttps = spdy.createServer(config, requestListener);
if (typeof config === "object") {
@@ -42,7 +42,7 @@ class Server extends net.Server {
}
}
}
-inherits(Server, https.Server);
+
function createServer(
config: ServerOptions,
requestListener: http.RequestListener
From aca6da61ee6abc91f648708c8a8a47890ce20628 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 18:40:01 +0800
Subject: [PATCH 014/125] Update index.ts
---
lib/index.ts | 82 +++++++++++++++++++++++++---------------------------
1 file changed, 40 insertions(+), 42 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 31c60c6..de2dc8a 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,52 +1,50 @@
+import events from "events";
import http from "http";
+import https from "https";
import net from "net";
import spdy from "spdy";
-import events from "events";
-import https from "https";
-import tls from "tls";
type ServerOptions = https.ServerOptions;
-class Server extends tls.Server {
- constructor(config: ServerOptions, requestListener: http.RequestListener) {
- super(config);
- const serverhttp = http.createServer(config, requestListener);
- const serverhttps = spdy.createServer(config, requestListener);
- if (typeof config === "object") {
- events.EventEmitter.prototype.removeAllListeners.call(
- this,
- "connection"
- );
- const connectionListener = function (socket: net.Socket) {
- socket.on("error", function onError() {});
- socket.once("data", (data) => {
- socket.pause();
-
- const firstByte = data[0];
- socket.unshift(data);
-
- if (firstByte === 22) {
- serverhttps.emit("connection", socket);
- } else if (32 < firstByte && firstByte < 127) {
- serverhttp.emit("connection", socket);
- }
-
- socket.resume();
- });
- };
- events.EventEmitter.prototype.on.call(
- this,
- "connection",
- connectionListener
- );
- } else {
- throw new Error("options are required!");
- }
- }
-}
function createServer(
config: ServerOptions,
requestListener: http.RequestListener
) {
- return new Server(config, requestListener);
+ if (!(typeof config === "object")) {
+ throw new Error("options are required!");
+ }
+ const serverhttp = http.createServer(config, requestListener);
+ const serverspdy = spdy.createServer(config, requestListener);
+
+ const onconnection = serverspdy.listeners("connection");
+ events.EventEmitter.prototype.removeAllListeners.call(
+ serverspdy,
+ "connection"
+ );
+
+ const connectionListener = function (socket: net.Socket) {
+ socket.on("error", function onError() {});
+ socket.once("data", (data) => {
+ socket.pause();
+
+ const firstByte = data[0];
+ socket.unshift(data);
+
+ if (firstByte === 22) {
+ onconnection.forEach((listener) => {
+ listener.call(serverspdy, socket);
+ });
+ } else if (32 < firstByte && firstByte < 127) {
+ serverhttp.emit("connection", socket);
+ }
+ socket.resume();
+ });
+ };
+ events.EventEmitter.prototype.on.call(
+ serverspdy,
+ "connection",
+ connectionListener
+ );
+
+ return serverspdy;
}
-export { createServer, Server };
+export { createServer };
From a8bbadcc7644e20e20390330dfcd4432267b1bb9 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 18:41:06 +0800
Subject: [PATCH 015/125] =?UTF-8?q?=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 10 +++-----
lib/index.js | 66 +++++++++++++++++++++-----------------------------
2 files changed, 31 insertions(+), 45 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 8d8a7a2..f2748dc 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,10 +1,6 @@
///
import http from "http";
-import net from "net";
import https from "https";
-declare type ServerOptions = http.ServerOptions & https.ServerOptions;
-declare class Server extends net.Server {
- constructor(config: ServerOptions, requestListener: http.RequestListener);
-}
-declare function createServer(config: ServerOptions, requestListener: http.RequestListener): Server;
-export { createServer, Server };
+declare type ServerOptions = https.ServerOptions;
+declare function createServer(config: ServerOptions, requestListener: http.RequestListener): https.Server;
+export { createServer };
diff --git a/lib/index.js b/lib/index.js
index a86c909..b35ba2d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,42 +1,32 @@
+import events from "events";
import http from "http";
-import net from "net";
import spdy from "spdy";
-import events from "events";
-import https from "https";
-import { inherits } from "util";
-class Server extends net.Server {
- constructor(config, requestListener) {
- super();
- const serverhttp = http.createServer(config, requestListener);
- const serverhttps = spdy.createServer(config, requestListener);
- if (typeof config === "object") {
- events.EventEmitter.prototype.removeAllListeners.call(this, "connection");
- const connectionListener = function (socket) {
- socket.on("error", function onError() { });
- socket.once("data", (data) => {
- const firstByte = data[0];
- socket.unshift(data);
- if (firstByte === 22) {
- serverhttps.emit("connection", socket);
- }
- else if (32 < firstByte && firstByte < 127) {
- serverhttp.emit("connection", socket);
- }
- else {
- socket.end();
- return;
- }
- });
- };
- events.EventEmitter.prototype.on.call(this, "connection", connectionListener);
- }
- else {
- throw new Error("options are required!");
- }
- }
-}
-inherits(Server, https.Server);
function createServer(config, requestListener) {
- return new Server(config, requestListener);
+ if (!(typeof config === "object")) {
+ throw new Error("options are required!");
+ }
+ const serverhttp = http.createServer(config, requestListener);
+ const serverspdy = spdy.createServer(config, requestListener);
+ const onconnection = serverspdy.listeners("connection");
+ events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
+ const connectionListener = function (socket) {
+ socket.on("error", function onError() { });
+ socket.once("data", (data) => {
+ socket.pause();
+ const firstByte = data[0];
+ socket.unshift(data);
+ if (firstByte === 22) {
+ onconnection.forEach((listener) => {
+ listener.call(serverspdy, socket);
+ });
+ }
+ else if (32 < firstByte && firstByte < 127) {
+ serverhttp.emit("connection", socket);
+ }
+ socket.resume();
+ });
+ };
+ events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
+ return serverspdy;
}
-export { createServer, Server };
+export { createServer };
From bfd419709785b41b2ee50bd1983c0305b60ff653 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 19:12:11 +0800
Subject: [PATCH 016/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 62 ++++++++++++++++++++++++++++++++++++++++------------
lib/index.ts | 50 +++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 27 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index b35ba2d..8018243 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,6 +1,7 @@
import events from "events";
import http from "http";
import spdy from "spdy";
+import stream from "stream";
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -8,25 +9,58 @@ function createServer(config, requestListener) {
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
+ events.EventEmitter.prototype.removeAllListeners.call(
+ serverspdy,
+ "connection"
+ );
const connectionListener = function (socket) {
- socket.on("error", function onError() { });
- socket.once("data", (data) => {
- socket.pause();
- const firstByte = data[0];
- socket.unshift(data);
- if (firstByte === 22) {
- onconnection.forEach((listener) => {
- listener.call(serverspdy, socket);
- });
+ let firsthandle = true;
+ let ishttp = false;
+ let istls = false;
+ const streamhttp = new stream.Duplex();
+ const streamtls = new stream.Duplex();
+ streamhttp.on("data", (data) => {
+ debugger;
+ if (ishttp) {
+ socket.write(data);
}
- else if (32 < firstByte && firstByte < 127) {
- serverhttp.emit("connection", socket);
+ });
+ streamtls.on("data", (data) => {
+ debugger;
+ if (istls) {
+ socket.write(data);
+ }
+ });
+ serverhttp.emit("connection", streamhttp);
+ onconnection.forEach((listeners) =>
+ listeners.call(serverspdy, streamtls)
+ );
+ socket.on("error", function onError() {});
+ socket.on("data", (data) => {
+ if (firsthandle) {
+ debugger;
+ firsthandle = false;
+ const firstByte = data[0];
+ if (firstByte === 22) {
+ istls = true;
+ } else if (32 < firstByte && firstByte < 127) {
+ ishttp = true;
+ }
+ }
+ if (ishttp) {
+ streamhttp.write(data);
+ }
+ if (istls) {
+ streamtls.write(data);
}
- socket.resume();
+ debugger;
});
};
- events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
+ events.EventEmitter.prototype.on.call(
+ serverspdy,
+ "connection",
+ connectionListener
+ );
return serverspdy;
}
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index de2dc8a..810a21d 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,6 +3,8 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
+import stream from "stream";
+
type ServerOptions = https.ServerOptions;
function createServer(
@@ -22,21 +24,43 @@ function createServer(
);
const connectionListener = function (socket: net.Socket) {
- socket.on("error", function onError() {});
- socket.once("data", (data) => {
- socket.pause();
-
- const firstByte = data[0];
- socket.unshift(data);
+ let firsthandle = true;
+ let ishttp = false;
+ let istls = false;
+ const streamhttp = new stream.Duplex();
+ const streamtls = new stream.Duplex();
- if (firstByte === 22) {
- onconnection.forEach((listener) => {
- listener.call(serverspdy, socket);
- });
- } else if (32 < firstByte && firstByte < 127) {
- serverhttp.emit("connection", socket);
+ streamhttp.on("data", (data) => {
+ if (ishttp) {
+ socket.write(data);
+ }
+ });
+ streamtls.on("data", (data) => {
+ if (istls) {
+ socket.write(data);
+ }
+ });
+ serverhttp.emit("connection", streamhttp);
+ onconnection.forEach((listeners) =>
+ listeners.call(serverspdy, streamtls)
+ );
+ socket.on("error", function onError() {});
+ socket.on("data", (data) => {
+ if (firsthandle) {
+ firsthandle = false;
+ const firstByte = data[0];
+ if (firstByte === 22) {
+ istls = true;
+ } else if (32 < firstByte && firstByte < 127) {
+ ishttp = true;
+ }
+ }
+ if (ishttp) {
+ streamhttp.write(data);
+ }
+ if (istls) {
+ streamtls.write(data);
}
- socket.resume();
});
};
events.EventEmitter.prototype.on.call(
From 921e878d838d0358f043656c6c58a0b23606e196 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 19:16:54 +0800
Subject: [PATCH 017/125] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 20 ++++++++++++++------
lib/index.ts | 16 +++++++++++++---
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 8018243..fd2e93a 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,7 +1,7 @@
import events from "events";
import http from "http";
+import net from "net";
import spdy from "spdy";
-import stream from "stream";
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -17,28 +17,36 @@ function createServer(config, requestListener) {
let firsthandle = true;
let ishttp = false;
let istls = false;
- const streamhttp = new stream.Duplex();
- const streamtls = new stream.Duplex();
+ const streamhttp = new net.Socket();
+ const streamtls = new net.Socket();
streamhttp.on("data", (data) => {
- debugger;
if (ishttp) {
socket.write(data);
}
});
+ streamhttp.on("end", () => {
+ if (ishttp) {
+ socket.end();
+ }
+ });
streamtls.on("data", (data) => {
- debugger;
if (istls) {
socket.write(data);
}
});
+ streamtls.on("end", () => {
+ if (istls) {
+ socket.end();
+ }
+ });
serverhttp.emit("connection", streamhttp);
onconnection.forEach((listeners) =>
listeners.call(serverspdy, streamtls)
);
socket.on("error", function onError() {});
socket.on("data", (data) => {
+ debugger;
if (firsthandle) {
- debugger;
firsthandle = false;
const firstByte = data[0];
if (firstByte === 22) {
diff --git a/lib/index.ts b/lib/index.ts
index 810a21d..dfdf32c 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,7 +3,6 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-import stream from "stream";
type ServerOptions = https.ServerOptions;
@@ -27,19 +26,29 @@ function createServer(
let firsthandle = true;
let ishttp = false;
let istls = false;
- const streamhttp = new stream.Duplex();
- const streamtls = new stream.Duplex();
+ const streamhttp = new net.Socket();
+ const streamtls = new net.Socket();
streamhttp.on("data", (data) => {
if (ishttp) {
socket.write(data);
}
});
+ streamhttp.on("end", () => {
+ if (ishttp) {
+ socket.end();
+ }
+ });
streamtls.on("data", (data) => {
if (istls) {
socket.write(data);
}
});
+ streamtls.on("end", () => {
+ if (istls) {
+ socket.end();
+ }
+ });
serverhttp.emit("connection", streamhttp);
onconnection.forEach((listeners) =>
listeners.call(serverspdy, streamtls)
@@ -72,3 +81,4 @@ function createServer(
return serverspdy;
}
export { createServer };
+
From eef3695537f96800d61e9bb6b5a66ed898f77152 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 19:53:13 +0800
Subject: [PATCH 018/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 63 ++++++++++++++++++++++++---------------------------
lib/index.ts | 60 ++++++++++++++++++++++++++++--------------------
tsconfig.json | 2 +-
3 files changed, 66 insertions(+), 59 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index fd2e93a..3419798 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,7 +1,7 @@
import events from "events";
import http from "http";
-import net from "net";
import spdy from "spdy";
+import { Duplex } from "stream";
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -9,41 +9,36 @@ function createServer(config, requestListener) {
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(
- serverspdy,
- "connection"
- );
+ events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
const connectionListener = function (socket) {
let firsthandle = true;
let ishttp = false;
let istls = false;
- const streamhttp = new net.Socket();
- const streamtls = new net.Socket();
- streamhttp.on("data", (data) => {
+ const streamhttp = new Duplex();
+ const streamtls = new Duplex();
+ Reflect.set(streamhttp, "write", function (chunk, encoding, callback) {
+ var _a;
+ debugger;
if (ishttp) {
- socket.write(data);
+ return socket.write(chunk, encoding, callback);
}
- });
- streamhttp.on("end", () => {
- if (ishttp) {
- socket.end();
+ else {
+ (_a = callback) === null || _a === void 0 ? void 0 : _a();
+ return true;
}
});
- streamtls.on("data", (data) => {
+ Reflect.set(streamtls, "write", function (chunk, encoding, callback) {
+ var _a;
+ debugger;
if (istls) {
- socket.write(data);
+ return socket.write(chunk, encoding, callback);
}
- });
- streamtls.on("end", () => {
- if (istls) {
- socket.end();
+ else {
+ (_a = callback) === null || _a === void 0 ? void 0 : _a();
+ return true;
}
});
- serverhttp.emit("connection", streamhttp);
- onconnection.forEach((listeners) =>
- listeners.call(serverspdy, streamtls)
- );
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
socket.on("data", (data) => {
debugger;
if (firsthandle) {
@@ -51,24 +46,26 @@ function createServer(config, requestListener) {
const firstByte = data[0];
if (firstByte === 22) {
istls = true;
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
ishttp = true;
}
+ if (ishttp) {
+ serverhttp.emit("connection", streamhttp);
+ }
+ if (istls) {
+ onconnection.forEach((listeners) => listeners.call(serverspdy, streamtls));
+ }
}
if (ishttp) {
- streamhttp.write(data);
+ streamhttp.emit("data", data);
}
if (istls) {
- streamtls.write(data);
+ streamtls.emit("data", data);
}
- debugger;
});
};
- events.EventEmitter.prototype.on.call(
- serverspdy,
- "connection",
- connectionListener
- );
+ events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
return serverspdy;
}
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index dfdf32c..ddefd62 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,7 +3,7 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-
+import { Duplex } from "stream";
type ServerOptions = https.ServerOptions;
function createServer(
@@ -26,35 +26,38 @@ function createServer(
let firsthandle = true;
let ishttp = false;
let istls = false;
- const streamhttp = new net.Socket();
- const streamtls = new net.Socket();
-
- streamhttp.on("data", (data) => {
- if (ishttp) {
- socket.write(data);
- }
- });
- streamhttp.on("end", () => {
+ const streamhttp = new Duplex();
+ const streamtls = new Duplex();
+ Reflect.set(streamhttp, "write", function (
+ chunk: string | Uint8Array,
+ encoding: string | undefined,
+ callback: ((err?: Error | undefined) => void) | undefined
+ ) {
+ debugger;
if (ishttp) {
- socket.end();
- }
- });
- streamtls.on("data", (data) => {
- if (istls) {
- socket.write(data);
+ return socket.write(chunk, encoding, callback);
+ } else {
+ callback?.();
+ return true;
}
});
- streamtls.on("end", () => {
+ Reflect.set(streamtls, "write", function (
+ chunk: string | Uint8Array,
+ encoding: string | undefined,
+ callback: ((err?: Error | undefined) => void) | undefined
+ ) {
+ debugger;
if (istls) {
- socket.end();
+ return socket.write(chunk, encoding, callback);
+ } else {
+ callback?.();
+ return true;
}
});
- serverhttp.emit("connection", streamhttp);
- onconnection.forEach((listeners) =>
- listeners.call(serverspdy, streamtls)
- );
+
socket.on("error", function onError() {});
socket.on("data", (data) => {
+ debugger;
if (firsthandle) {
firsthandle = false;
const firstByte = data[0];
@@ -63,12 +66,20 @@ function createServer(
} else if (32 < firstByte && firstByte < 127) {
ishttp = true;
}
+ if (ishttp) {
+ serverhttp.emit("connection", streamhttp);
+ }
+ if (istls) {
+ onconnection.forEach((listeners) =>
+ listeners.call(serverspdy, streamtls)
+ );
+ }
}
if (ishttp) {
- streamhttp.write(data);
+ streamhttp.emit("data", data);
}
if (istls) {
- streamtls.write(data);
+ streamtls.emit("data", data);
}
});
};
@@ -81,4 +92,3 @@ function createServer(
return serverspdy;
}
export { createServer };
-
diff --git a/tsconfig.json b/tsconfig.json
index 96c8708..84796e7 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,7 +12,7 @@
"checkJs": false,
"charset": "utf-8",
"strict": true,
- "target": "ESNEXT",
+ "target": "es2019",
"module": "ESNEXT",
"importHelpers": true,
"noImplicitAny": true,
From 6b6e665450967b6a45e7e2df0f30154ca1dbce7d Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 20:16:55 +0800
Subject: [PATCH 019/125] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0htt?=
=?UTF-8?q?p?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 13 ++++++-------
lib/index.ts | 8 +++++---
package.json | 5 ++++-
yarn.lock | 10 ++++++++++
4 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 3419798..279ddc1 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -17,30 +17,27 @@ function createServer(config, requestListener) {
const streamhttp = new Duplex();
const streamtls = new Duplex();
Reflect.set(streamhttp, "write", function (chunk, encoding, callback) {
- var _a;
- debugger;
if (ishttp) {
+ console.log("http data write", chunk);
return socket.write(chunk, encoding, callback);
}
else {
- (_a = callback) === null || _a === void 0 ? void 0 : _a();
+ callback === null || callback === void 0 ? void 0 : callback();
return true;
}
});
Reflect.set(streamtls, "write", function (chunk, encoding, callback) {
- var _a;
- debugger;
if (istls) {
+ console.log("tls data write", chunk);
return socket.write(chunk, encoding, callback);
}
else {
- (_a = callback) === null || _a === void 0 ? void 0 : _a();
+ callback === null || callback === void 0 ? void 0 : callback();
return true;
}
});
socket.on("error", function onError() { });
socket.on("data", (data) => {
- debugger;
if (firsthandle) {
firsthandle = false;
const firstByte = data[0];
@@ -59,9 +56,11 @@ function createServer(config, requestListener) {
}
if (ishttp) {
streamhttp.emit("data", data);
+ console.log("http data recv", data);
}
if (istls) {
streamtls.emit("data", data);
+ console.log("tls data recv", data);
}
});
};
diff --git a/lib/index.ts b/lib/index.ts
index ddefd62..801ec4a 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -28,13 +28,14 @@ function createServer(
let istls = false;
const streamhttp = new Duplex();
const streamtls = new Duplex();
+
Reflect.set(streamhttp, "write", function (
chunk: string | Uint8Array,
encoding: string | undefined,
callback: ((err?: Error | undefined) => void) | undefined
) {
- debugger;
if (ishttp) {
+ console.log("http data write", chunk);
return socket.write(chunk, encoding, callback);
} else {
callback?.();
@@ -46,8 +47,8 @@ function createServer(
encoding: string | undefined,
callback: ((err?: Error | undefined) => void) | undefined
) {
- debugger;
if (istls) {
+ console.log("tls data write", chunk);
return socket.write(chunk, encoding, callback);
} else {
callback?.();
@@ -57,7 +58,6 @@ function createServer(
socket.on("error", function onError() {});
socket.on("data", (data) => {
- debugger;
if (firsthandle) {
firsthandle = false;
const firstByte = data[0];
@@ -77,9 +77,11 @@ function createServer(
}
if (ishttp) {
streamhttp.emit("data", data);
+ console.log("http data recv", data);
}
if (istls) {
streamtls.emit("data", data);
+ console.log("tls data recv", data);
}
});
};
diff --git a/package.json b/package.json
index 73190c0..f41e69a 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,10 @@
"@types/spdy": "^3.4.4"
},
"devDependencies": {
- "prettier": "^2.0.4"
+ "spdy": "^4.0.2",
+ "prettier": "^2.0.4",
+ "tslib": "^1.11.1",
+ "typescript": "^3.8.3"
},
"license": "ISC",
"repository": {
diff --git a/yarn.lock b/yarn.lock
index db6989b..830dfb9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -160,6 +160,16 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"
+tslib@^1.11.1:
+ version "1.11.1"
+ resolved "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
+ integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==
+
+typescript@^3.8.3:
+ version "3.8.3"
+ resolved "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
+ integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
+
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
From e5ca08105103176982818f6a90d6a104a526e29e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 20:57:25 +0800
Subject: [PATCH 020/125] Update index.ts
---
lib/index.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 801ec4a..977edac 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -26,8 +26,50 @@ function createServer(
let firsthandle = true;
let ishttp = false;
let istls = false;
- const streamhttp = new Duplex();
- const streamtls = new Duplex();
+
+ const streamhttp = new Duplex({
+ write(
+ chunk: any,
+ encoding: string,
+ callback: (error?: Error | null | undefined) => void
+ ) {},
+ writev(
+ chunks: {
+ chunk: any;
+ encoding: string;
+ }[],
+ callback: (error?: Error | null | undefined) => void
+ ) {},
+
+ final(callback: (error?: Error | null | undefined) => void) {},
+ read(size: number) {},
+ destroy(
+ error: Error | null,
+ callback: (error: Error | null) => void
+ ) {},
+ });
+
+ const streamtls = new Duplex({
+ write(
+ chunk: any,
+ encoding: string,
+ callback: (error?: Error | null | undefined) => void
+ ) {},
+ writev(
+ chunks: {
+ chunk: any;
+ encoding: string;
+ }[],
+ callback: (error?: Error | null | undefined) => void
+ ) {},
+
+ final(callback: (error?: Error | null | undefined) => void) {},
+ read(size: number) {},
+ destroy(
+ error: Error | null,
+ callback: (error: Error | null) => void
+ ) {},
+ });
Reflect.set(streamhttp, "write", function (
chunk: string | Uint8Array,
From 1f8c6acb5dc114c381165adf5286f0cf638f1106 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 21:21:25 +0800
Subject: [PATCH 021/125] =?UTF-8?q?=E7=BB=88=E4=BA=8E=E6=88=90=E5=8A=9F?=
=?UTF-8?q?=E4=BA=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +
lib/index.js | 68 ++++++----------
lib/index.ts | 215 +++++++++++++++++++++++++++++----------------------
3 files changed, 146 insertions(+), 139 deletions(-)
diff --git a/README.md b/README.md
index 974be62..95136e7 100644
--- a/README.md
+++ b/README.md
@@ -80,3 +80,5 @@ httpolyglot
https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
TLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See [this comment](https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155) for more information.
+
+https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js
diff --git a/lib/index.js b/lib/index.js
index 279ddc1..6e55d0d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,7 +1,6 @@
import events from "events";
import http from "http";
import spdy from "spdy";
-import { Duplex } from "stream";
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -10,59 +9,38 @@ function createServer(config, requestListener) {
const serverspdy = spdy.createServer(config, requestListener);
const onconnection = serverspdy.listeners("connection");
events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
+ function handletls(socket) {
+ onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
+ }
+ function handlehttp(socket) {
+ serverhttp.emit("connection", socket);
+ }
const connectionListener = function (socket) {
- let firsthandle = true;
+ socket.on("error", function onError() { });
let ishttp = false;
let istls = false;
- const streamhttp = new Duplex();
- const streamtls = new Duplex();
- Reflect.set(streamhttp, "write", function (chunk, encoding, callback) {
- if (ishttp) {
- console.log("http data write", chunk);
- return socket.write(chunk, encoding, callback);
- }
- else {
- callback === null || callback === void 0 ? void 0 : callback();
- return true;
+ const data = socket.read(1);
+ if (data === null) {
+ socket.once("readable", () => {
+ connectionListener(socket);
+ });
+ }
+ else {
+ const firstByte = data[0];
+ socket.unshift(data);
+ if (firstByte === 22) {
+ istls = true;
}
- });
- Reflect.set(streamtls, "write", function (chunk, encoding, callback) {
- if (istls) {
- console.log("tls data write", chunk);
- return socket.write(chunk, encoding, callback);
- }
- else {
- callback === null || callback === void 0 ? void 0 : callback();
- return true;
- }
- });
- socket.on("error", function onError() { });
- socket.on("data", (data) => {
- if (firsthandle) {
- firsthandle = false;
- const firstByte = data[0];
- if (firstByte === 22) {
- istls = true;
- }
- else if (32 < firstByte && firstByte < 127) {
- ishttp = true;
- }
- if (ishttp) {
- serverhttp.emit("connection", streamhttp);
- }
- if (istls) {
- onconnection.forEach((listeners) => listeners.call(serverspdy, streamtls));
- }
+ else if (32 < firstByte && firstByte < 127) {
+ ishttp = true;
}
if (ishttp) {
- streamhttp.emit("data", data);
- console.log("http data recv", data);
+ handlehttp(socket);
}
if (istls) {
- streamtls.emit("data", data);
- console.log("tls data recv", data);
+ handletls(socket);
}
- });
+ }
};
events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
return serverspdy;
diff --git a/lib/index.ts b/lib/index.ts
index 977edac..297906b 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,7 +3,7 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-import { Duplex } from "stream";
+// import { Duplex } from "stream";
type ServerOptions = https.ServerOptions;
function createServer(
@@ -21,111 +21,138 @@ function createServer(
serverspdy,
"connection"
);
-
+ function handletls(socket: net.Socket) {
+ onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
+ }
+ function handlehttp(socket: net.Socket) {
+ serverhttp.emit("connection", socket);
+ }
const connectionListener = function (socket: net.Socket) {
- let firsthandle = true;
+ socket.on("error", function onError() {});
+ // let firsthandle = true;
let ishttp = false;
let istls = false;
-
- const streamhttp = new Duplex({
- write(
- chunk: any,
- encoding: string,
- callback: (error?: Error | null | undefined) => void
- ) {},
- writev(
- chunks: {
- chunk: any;
- encoding: string;
- }[],
- callback: (error?: Error | null | undefined) => void
- ) {},
- final(callback: (error?: Error | null | undefined) => void) {},
- read(size: number) {},
- destroy(
- error: Error | null,
- callback: (error: Error | null) => void
- ) {},
- });
-
- const streamtls = new Duplex({
- write(
- chunk: any,
- encoding: string,
- callback: (error?: Error | null | undefined) => void
- ) {},
- writev(
- chunks: {
- chunk: any;
- encoding: string;
- }[],
- callback: (error?: Error | null | undefined) => void
- ) {},
+ // const streamhttp = new Duplex({
+ // write(
+ // chunk: any,
+ // encoding: string,
+ // callback: (error?: Error | null | undefined) => void
+ // ) {},
+ // writev(
+ // chunks: {
+ // chunk: any;
+ // encoding: string;
+ // }[],
+ // callback: (error?: Error | null | undefined) => void
+ // ) {},
- final(callback: (error?: Error | null | undefined) => void) {},
- read(size: number) {},
- destroy(
- error: Error | null,
- callback: (error: Error | null) => void
- ) {},
- });
+ // final(callback: (error?: Error | null | undefined) => void) {},
+ // read(size: number) {},
+ // destroy(
+ // error: Error | null,
+ // callback: (error: Error | null) => void
+ // ) {},
+ // });
- Reflect.set(streamhttp, "write", function (
- chunk: string | Uint8Array,
- encoding: string | undefined,
- callback: ((err?: Error | undefined) => void) | undefined
- ) {
- if (ishttp) {
- console.log("http data write", chunk);
- return socket.write(chunk, encoding, callback);
- } else {
- callback?.();
- return true;
- }
- });
- Reflect.set(streamtls, "write", function (
- chunk: string | Uint8Array,
- encoding: string | undefined,
- callback: ((err?: Error | undefined) => void) | undefined
- ) {
- if (istls) {
- console.log("tls data write", chunk);
- return socket.write(chunk, encoding, callback);
- } else {
- callback?.();
- return true;
- }
- });
+ // const streamtls = new Duplex({
+ // write(
+ // chunk: any,
+ // encoding: string,
+ // callback: (error?: Error | null | undefined) => void
+ // ) {},
+ // writev(
+ // chunks: {
+ // chunk: any;
+ // encoding: string;
+ // }[],
+ // callback: (error?: Error | null | undefined) => void
+ // ) {},
- socket.on("error", function onError() {});
- socket.on("data", (data) => {
- if (firsthandle) {
- firsthandle = false;
- const firstByte = data[0];
- if (firstByte === 22) {
- istls = true;
- } else if (32 < firstByte && firstByte < 127) {
- ishttp = true;
- }
- if (ishttp) {
- serverhttp.emit("connection", streamhttp);
- }
- if (istls) {
- onconnection.forEach((listeners) =>
- listeners.call(serverspdy, streamtls)
- );
- }
+ // final(callback: (error?: Error | null | undefined) => void) {},
+ // read(size: number) {},
+ // destroy(
+ // error: Error | null,
+ // callback: (error: Error | null) => void
+ // ) {},
+ // });
+
+ // Reflect.set(streamhttp, "write", function (
+ // chunk: string | Uint8Array,
+ // encoding: string | undefined,
+ // callback: ((err?: Error | undefined) => void) | undefined
+ // ) {
+ // if (ishttp) {
+ // console.log("http data write", chunk);
+ // return socket.write(chunk, encoding, callback);
+ // } else {
+ // callback?.();
+ // return true;
+ // }
+ // });
+ // Reflect.set(streamtls, "write", function (
+ // chunk: string | Uint8Array,
+ // encoding: string | undefined,
+ // callback: ((err?: Error | undefined) => void) | undefined
+ // ) {
+ // if (istls) {
+ // console.log("tls data write", chunk);
+ // return socket.write(chunk, encoding, callback);
+ // } else {
+ // callback?.();
+ // return true;
+ // }
+ // });
+ const data = socket.read(1);
+ /* https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js */
+ if (data === null) {
+ socket.once("readable", () => {
+ connectionListener(socket);
+ });
+ } else {
+ const firstByte = data[0];
+ socket.unshift(data);
+ if (firstByte === 22) {
+ istls = true;
+ } else if (32 < firstByte && firstByte < 127) {
+ ishttp = true;
}
if (ishttp) {
- streamhttp.emit("data", data);
- console.log("http data recv", data);
+ handlehttp(socket);
}
if (istls) {
- streamtls.emit("data", data);
- console.log("tls data recv", data);
+ handletls(socket);
}
- });
+ }
+ /* 测试发现不能使用on data事件,会收不到响应 */
+ // socket.once("data", (data) => {
+ // if (firsthandle) {
+ // firsthandle = false;
+ // // const firstByte = data[0];
+ // // socket.unshift(data);
+ // // if (firstByte === 22) {
+ // // istls = true;
+ // // } else if (32 < firstByte && firstByte < 127) {
+ // // ishttp = true;
+ // // }
+ // // if (ishttp) {
+ // // serverhttp.emit("connection", socket);
+ // // }
+ // // if (istls) {
+ // // onconnection.forEach((listeners) =>
+ // // listeners.call(serverspdy, socket)
+ // // );
+ // // }
+ // }
+ // // if (ishttp) {
+ // // streamhttp.emit("data", data);
+ // // console.log("http data recv", data);
+ // // }
+ // // if (istls) {
+ // // streamtls.emit("data", data);
+ // // console.log("tls data recv", data);
+ // // }
+ // });
};
events.EventEmitter.prototype.on.call(
serverspdy,
From 558c36439c5d0259f005fd9e8ba6a4af2f3cdbf2 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 21:22:41 +0800
Subject: [PATCH 022/125] Update README.md
---
README.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/README.md b/README.md
index 95136e7..27f5257 100644
--- a/README.md
+++ b/README.md
@@ -71,8 +71,6 @@ httpolyglot
## Exports
-- **Server** - A class similar to https.Server .
-
- **createServer** - Creates and returns a new Server instance.
# How it Works
From 4b1c7dda7ea37a12ae4e1dfc37b07604277c2c73 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 21:23:45 +0800
Subject: [PATCH 023/125] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 27f5257..43cdf43 100644
--- a/README.md
+++ b/README.md
@@ -77,6 +77,8 @@ httpolyglot
https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
-TLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See [this comment](https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155) for more information.
+TLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See this comment for more information.
+
+https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155
https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js
From deda8c6fa2e86c80266e2a7f29388c2f9c949fae Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 21:26:55 +0800
Subject: [PATCH 024/125] Update README.md
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index 43cdf43..5224657 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,8 @@ httpolyglot
## Exports
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/lib/index.d.ts
+
- **createServer** - Creates and returns a new Server instance.
# How it Works
From 6f38adfc3855e0268fa2351691c88c5d99624a19 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:08:01 +0800
Subject: [PATCH 025/125] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 5 ++++-
lib/index.js | 19 ++++++++++++-------
test/one.js | 4 +++-
test/two.js | 2 +-
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index f2748dc..a69324b 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,5 +2,8 @@
import http from "http";
import https from "https";
declare type ServerOptions = https.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener: http.RequestListener): https.Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener: http.RequestListener
+): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 6e55d0d..c771872 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -8,7 +8,10 @@ function createServer(config, requestListener) {
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
+ events.EventEmitter.prototype.removeAllListeners.call(
+ serverspdy,
+ "connection"
+ );
function handletls(socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
@@ -16,7 +19,7 @@ function createServer(config, requestListener) {
serverhttp.emit("connection", socket);
}
const connectionListener = function (socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
let ishttp = false;
let istls = false;
const data = socket.read(1);
@@ -24,14 +27,12 @@ function createServer(config, requestListener) {
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
istls = true;
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
ishttp = true;
}
if (ishttp) {
@@ -42,7 +43,11 @@ function createServer(config, requestListener) {
}
}
};
- events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
+ events.EventEmitter.prototype.on.call(
+ serverspdy,
+ "connection",
+ connectionListener
+ );
return serverspdy;
}
export { createServer };
diff --git a/test/one.js b/test/one.js
index 5546d46..1bdc674 100644
--- a/test/one.js
+++ b/test/one.js
@@ -14,7 +14,9 @@ createServer(
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
- res.end((req.socket ? "HTTPS" : "HTTP") + " Connection!");
+ res.end(
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
+ );
}
).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
diff --git a/test/two.js b/test/two.js
index 40f734d..dbca2f9 100644
--- a/test/two.js
+++ b/test/two.js
@@ -13,7 +13,7 @@ createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
- if (!req.socket) {
+ if (!("encrypted" in req.socket)) {
const host = req.headers["host"];
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
From 38ed20ab1f53b8c5362eb00ab46e3774f5eb8ffa Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:09:52 +0800
Subject: [PATCH 026/125] Update README.md
---
README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 5224657..cb22e4b 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,9 @@ httpolyglot
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
- res.end((req.socket.encrypted ? "HTTPS" : "HTTP") + " Connection!");
+ res.end(
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
+ );
}
)
.listen(port, "localhost", function () {
@@ -49,7 +51,7 @@ httpolyglot
cert: fs.readFileSync("server.crt"),
},
function (req, res) {
- if (!req.socket.encrypted) {
+ if (!("encrypted" in req.socket)) {
const host = req.headers["host"];
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
From 5bae407e346a6120366e7d76a4c586ac9eb8ded0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:17:08 +0800
Subject: [PATCH 027/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 5 +--
lib/index.js | 24 +++++-----
lib/index.ts | 118 ++++---------------------------------------------
3 files changed, 21 insertions(+), 126 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index a69324b..f2748dc 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,8 +2,5 @@
import http from "http";
import https from "https";
declare type ServerOptions = https.ServerOptions;
-declare function createServer(
- config: ServerOptions,
- requestListener: http.RequestListener
-): https.Server;
+declare function createServer(config: ServerOptions, requestListener: http.RequestListener): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index c771872..e20cfba 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -7,11 +7,10 @@ function createServer(config, requestListener) {
}
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
+ events.EventEmitter.prototype.removeAllListeners.call(serverhttp, "request");
+ events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "request");
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(
- serverspdy,
- "connection"
- );
+ events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
function handletls(socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
@@ -19,7 +18,7 @@ function createServer(config, requestListener) {
serverhttp.emit("connection", socket);
}
const connectionListener = function (socket) {
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
let ishttp = false;
let istls = false;
const data = socket.read(1);
@@ -27,14 +26,19 @@ function createServer(config, requestListener) {
socket.once("readable", () => {
connectionListener(socket);
});
- } else {
+ }
+ else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
istls = true;
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
ishttp = true;
}
+ else {
+ socket.destroy();
+ }
if (ishttp) {
handlehttp(socket);
}
@@ -43,11 +47,7 @@ function createServer(config, requestListener) {
}
}
};
- events.EventEmitter.prototype.on.call(
- serverspdy,
- "connection",
- connectionListener
- );
+ events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
return serverspdy;
}
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index 297906b..0773ce4 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,7 +3,7 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-// import { Duplex } from "stream";
+const eventproto = events.EventEmitter.prototype;
type ServerOptions = https.ServerOptions;
function createServer(
@@ -15,12 +15,10 @@ function createServer(
}
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
-
+ eventproto.removeAllListeners.call(serverhttp, "request");
+ eventproto.removeAllListeners.call(serverspdy, "request");
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(
- serverspdy,
- "connection"
- );
+ eventproto.removeAllListeners.call(serverspdy, "connection");
function handletls(socket: net.Socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
@@ -29,80 +27,10 @@ function createServer(
}
const connectionListener = function (socket: net.Socket) {
socket.on("error", function onError() {});
- // let firsthandle = true;
+
let ishttp = false;
let istls = false;
- // const streamhttp = new Duplex({
- // write(
- // chunk: any,
- // encoding: string,
- // callback: (error?: Error | null | undefined) => void
- // ) {},
- // writev(
- // chunks: {
- // chunk: any;
- // encoding: string;
- // }[],
- // callback: (error?: Error | null | undefined) => void
- // ) {},
-
- // final(callback: (error?: Error | null | undefined) => void) {},
- // read(size: number) {},
- // destroy(
- // error: Error | null,
- // callback: (error: Error | null) => void
- // ) {},
- // });
-
- // const streamtls = new Duplex({
- // write(
- // chunk: any,
- // encoding: string,
- // callback: (error?: Error | null | undefined) => void
- // ) {},
- // writev(
- // chunks: {
- // chunk: any;
- // encoding: string;
- // }[],
- // callback: (error?: Error | null | undefined) => void
- // ) {},
-
- // final(callback: (error?: Error | null | undefined) => void) {},
- // read(size: number) {},
- // destroy(
- // error: Error | null,
- // callback: (error: Error | null) => void
- // ) {},
- // });
-
- // Reflect.set(streamhttp, "write", function (
- // chunk: string | Uint8Array,
- // encoding: string | undefined,
- // callback: ((err?: Error | undefined) => void) | undefined
- // ) {
- // if (ishttp) {
- // console.log("http data write", chunk);
- // return socket.write(chunk, encoding, callback);
- // } else {
- // callback?.();
- // return true;
- // }
- // });
- // Reflect.set(streamtls, "write", function (
- // chunk: string | Uint8Array,
- // encoding: string | undefined,
- // callback: ((err?: Error | undefined) => void) | undefined
- // ) {
- // if (istls) {
- // console.log("tls data write", chunk);
- // return socket.write(chunk, encoding, callback);
- // } else {
- // callback?.();
- // return true;
- // }
- // });
const data = socket.read(1);
/* https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js */
if (data === null) {
@@ -116,6 +44,8 @@ function createServer(
istls = true;
} else if (32 < firstByte && firstByte < 127) {
ishttp = true;
+ } else {
+ socket.destroy();
}
if (ishttp) {
handlehttp(socket);
@@ -125,40 +55,8 @@ function createServer(
}
}
/* 测试发现不能使用on data事件,会收不到响应 */
- // socket.once("data", (data) => {
- // if (firsthandle) {
- // firsthandle = false;
- // // const firstByte = data[0];
- // // socket.unshift(data);
- // // if (firstByte === 22) {
- // // istls = true;
- // // } else if (32 < firstByte && firstByte < 127) {
- // // ishttp = true;
- // // }
- // // if (ishttp) {
- // // serverhttp.emit("connection", socket);
- // // }
- // // if (istls) {
- // // onconnection.forEach((listeners) =>
- // // listeners.call(serverspdy, socket)
- // // );
- // // }
- // }
- // // if (ishttp) {
- // // streamhttp.emit("data", data);
- // // console.log("http data recv", data);
- // // }
- // // if (istls) {
- // // streamtls.emit("data", data);
- // // console.log("tls data recv", data);
- // // }
- // });
};
- events.EventEmitter.prototype.on.call(
- serverspdy,
- "connection",
- connectionListener
- );
+ eventproto.addListener.call(serverspdy, "connection", connectionListener);
return serverspdy;
}
From 7605a233a907d6e95f12a6c54d50dd09abdb1b02 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:19:13 +0800
Subject: [PATCH 028/125] Update index.js
---
lib/index.js | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index e20cfba..38b5c8d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,16 +1,17 @@
import events from "events";
import http from "http";
import spdy from "spdy";
+const eventproto = events.EventEmitter.prototype;
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
- events.EventEmitter.prototype.removeAllListeners.call(serverhttp, "request");
- events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "request");
+ eventproto.removeAllListeners.call(serverhttp, "request");
+ eventproto.removeAllListeners.call(serverspdy, "request");
const onconnection = serverspdy.listeners("connection");
- events.EventEmitter.prototype.removeAllListeners.call(serverspdy, "connection");
+ eventproto.removeAllListeners.call(serverspdy, "connection");
function handletls(socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
@@ -47,7 +48,7 @@ function createServer(config, requestListener) {
}
}
};
- events.EventEmitter.prototype.on.call(serverspdy, "connection", connectionListener);
+ eventproto.addListener.call(serverspdy, "connection", connectionListener);
return serverspdy;
}
export { createServer };
From 27182c1204332e7808e2639516e0015730ae419e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:32:07 +0800
Subject: [PATCH 029/125] Update index.ts
---
lib/index.ts | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 0773ce4..0143c54 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,9 +1,8 @@
-import events from "events";
import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-const eventproto = events.EventEmitter.prototype;
+
type ServerOptions = https.ServerOptions;
function createServer(
@@ -13,19 +12,35 @@ function createServer(
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
+ function onrequest(req: http.IncomingMessage, res: http.ServerResponse) {
+
+ requestListener(req, res);
+ }
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
- eventproto.removeAllListeners.call(serverhttp, "request");
- eventproto.removeAllListeners.call(serverspdy, "request");
+ serverhttp.removeAllListeners("request");
+ serverspdy.removeAllListeners("request");
+ serverspdy.addListener("request", onrequest);
+ serverhttp.addListener("request", (req, res) => {
+ serverspdy.emit("request", req, res);
+ });
+ serverhttp.addListener(
+ "upgrade",
+ (response: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
+ serverspdy.emit("upgrade", response, socket, head);
+ }
+ );
const onconnection = serverspdy.listeners("connection");
- eventproto.removeAllListeners.call(serverspdy, "connection");
+ serverspdy.removeAllListeners("connection");
function handletls(socket: net.Socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
function handlehttp(socket: net.Socket) {
serverhttp.emit("connection", socket);
}
- const connectionListener = function (socket: net.Socket) {
+ serverspdy.addListener("connection", connectionListener);
+
+ function connectionListener(socket: net.Socket) {
socket.on("error", function onError() {});
let ishttp = false;
@@ -55,8 +70,7 @@ function createServer(
}
}
/* 测试发现不能使用on data事件,会收不到响应 */
- };
- eventproto.addListener.call(serverspdy, "connection", connectionListener);
+ }
return serverspdy;
}
From 05e014b1f99bd25486f5ae940cef21e987f0a18a Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 22:33:05 +0800
Subject: [PATCH 030/125] Update index.js
---
lib/index.js | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 38b5c8d..d8f104d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,24 +1,33 @@
-import events from "events";
import http from "http";
import spdy from "spdy";
-const eventproto = events.EventEmitter.prototype;
function createServer(config, requestListener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
+ function onrequest(req, res) {
+ requestListener(req, res);
+ }
const serverhttp = http.createServer(config, requestListener);
const serverspdy = spdy.createServer(config, requestListener);
- eventproto.removeAllListeners.call(serverhttp, "request");
- eventproto.removeAllListeners.call(serverspdy, "request");
+ serverhttp.removeAllListeners("request");
+ serverspdy.removeAllListeners("request");
+ serverspdy.addListener("request", onrequest);
+ serverhttp.addListener("request", (req, res) => {
+ serverspdy.emit("request", req, res);
+ });
+ serverhttp.addListener("upgrade", (response, socket, head) => {
+ serverspdy.emit("upgrade", response, socket, head);
+ });
const onconnection = serverspdy.listeners("connection");
- eventproto.removeAllListeners.call(serverspdy, "connection");
+ serverspdy.removeAllListeners("connection");
function handletls(socket) {
onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
- const connectionListener = function (socket) {
+ serverspdy.addListener("connection", connectionListener);
+ function connectionListener(socket) {
socket.on("error", function onError() { });
let ishttp = false;
let istls = false;
@@ -47,8 +56,7 @@ function createServer(config, requestListener) {
handletls(socket);
}
}
- };
- eventproto.addListener.call(serverspdy, "connection", connectionListener);
+ }
return serverspdy;
}
export { createServer };
From 10970024dbafddc58c7858b7629c40ac39588fb2 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:01:23 +0800
Subject: [PATCH 031/125] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86upgradeListe?=
=?UTF-8?q?ner?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 3 ++-
lib/index.js | 27 +++++++++++++++++----------
lib/index.ts | 45 +++++++++++++++++++++++++++++++++------------
test/test.js | 1 +
test/three.js | 35 +++++++++++++++++++++++++++++++++++
5 files changed, 88 insertions(+), 23 deletions(-)
create mode 100644 test/three.js
diff --git a/lib/index.d.ts b/lib/index.d.ts
index f2748dc..9b906dc 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,6 +1,7 @@
///
import http from "http";
import https from "https";
+import net from "net";
declare type ServerOptions = https.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener: http.RequestListener): https.Server;
+declare function createServer(config: ServerOptions, requestListener?: http.RequestListener, upgradeListener?: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void): any;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index d8f104d..1782278 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,27 +1,34 @@
import http from "http";
import spdy from "spdy";
-function createServer(config, requestListener) {
+const notfoundrequestlistener = function (req, res) {
+ res.statusCode = 404;
+ res.write(404);
+ res.end();
+};
+const notfoundupgradelistener = function (req, socket, head) {
+ socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
+ socket.destroy();
+};
+function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
- function onrequest(req, res) {
- requestListener(req, res);
- }
- const serverhttp = http.createServer(config, requestListener);
- const serverspdy = spdy.createServer(config, requestListener);
+ const serverhttp = http.createServer(config);
+ const serverspdy = spdy.createServer(config);
serverhttp.removeAllListeners("request");
serverspdy.removeAllListeners("request");
- serverspdy.addListener("request", onrequest);
+ serverspdy.addListener("request", requestListener);
serverhttp.addListener("request", (req, res) => {
serverspdy.emit("request", req, res);
});
- serverhttp.addListener("upgrade", (response, socket, head) => {
- serverspdy.emit("upgrade", response, socket, head);
+ serverhttp.addListener("upgrade", (req, socket, head) => {
+ serverspdy.emit("upgrade", req, socket, head);
});
+ serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
+ onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
diff --git a/lib/index.ts b/lib/index.ts
index 0143c54..aa2eba1 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -4,36 +4,57 @@ import net from "net";
import spdy from "spdy";
type ServerOptions = https.ServerOptions;
-
+const notfoundrequestlistener = function (
+ req: http.IncomingMessage,
+ res: http.ServerResponse
+) {
+ res.statusCode = 404;
+ res.write(404);
+ res.end();
+};
+const notfoundupgradelistener = function (
+ req: http.IncomingMessage,
+ socket: net.Socket,
+ head: Buffer
+) {
+ socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
+ socket.destroy();
+};
function createServer(
config: ServerOptions,
- requestListener: http.RequestListener
+ requestListener: http.RequestListener = notfoundrequestlistener,
+ upgradeListener: (
+ req: http.IncomingMessage,
+ socket: net.Socket,
+ head: Buffer
+ ) => void = notfoundupgradelistener
) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
- function onrequest(req: http.IncomingMessage, res: http.ServerResponse) {
-
- requestListener(req, res);
- }
- const serverhttp = http.createServer(config, requestListener);
- const serverspdy = spdy.createServer(config, requestListener);
+
+ const serverhttp = http.createServer(config);
+ //@ts-ignore
+ const serverspdy = spdy.createServer(config);
serverhttp.removeAllListeners("request");
serverspdy.removeAllListeners("request");
- serverspdy.addListener("request", onrequest);
+ serverspdy.addListener("request", requestListener);
serverhttp.addListener("request", (req, res) => {
serverspdy.emit("request", req, res);
});
serverhttp.addListener(
"upgrade",
- (response: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
- serverspdy.emit("upgrade", response, socket, head);
+ (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
+ serverspdy.emit("upgrade", req, socket, head);
}
);
+ serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket: net.Socket) {
- onconnection.forEach((listeners) => listeners.call(serverspdy, socket));
+ onconnection.forEach((listeners:Function) =>
+ Reflect.apply(listeners, serverspdy, [socket])
+ );
}
function handlehttp(socket: net.Socket) {
serverhttp.emit("connection", socket);
diff --git a/test/test.js b/test/test.js
index 6203bcd..8b411a7 100755
--- a/test/test.js
+++ b/test/test.js
@@ -1,2 +1,3 @@
import "./one.js";
import "./two.js";
+import "./three.js";
diff --git a/test/three.js b/test/three.js
new file mode 100644
index 0000000..bde74df
--- /dev/null
+++ b/test/three.js
@@ -0,0 +1,35 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 8999;
+import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+const server = createServer(
+ {
+ key: fs.readFileSync(path.join(__dirname, "server.key")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ },
+ function (req, res) {
+ console.log(req, res);
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("websocket");
+ },
+ function (req, socket, head) {
+ console.log(req, head);
+ socket.write(
+ "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
+ "Upgrade: WebSocket\r\n" +
+ "Connection: Upgrade\r\n" +
+ "\r\n"
+ );
+
+ socket.pipe(socket);
+ }
+);
+
+server.listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
From f5604bf83b28053e01f8e9628994f23d17cef7f4 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:10:54 +0800
Subject: [PATCH 032/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 10 +++++++++-
lib/index.js | 23 +++++++++++++----------
lib/index.ts | 4 ++--
test/test.js | 1 +
test/three.js | 2 --
test/zero.js | 15 +++++++++++++++
6 files changed, 40 insertions(+), 15 deletions(-)
create mode 100644 test/zero.js
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 9b906dc..7e60238 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -3,5 +3,13 @@ import http from "http";
import https from "https";
import net from "net";
declare type ServerOptions = https.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener?: http.RequestListener, upgradeListener?: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void): any;
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: http.RequestListener,
+ upgradeListener?: (
+ req: http.IncomingMessage,
+ socket: net.Socket,
+ head: Buffer
+ ) => void
+): any;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 1782278..88c4f89 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,14 +2,18 @@ import http from "http";
import spdy from "spdy";
const notfoundrequestlistener = function (req, res) {
res.statusCode = 404;
- res.write(404);
+ res.write("404");
res.end();
};
const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
+function createServer(
+ config,
+ requestListener = notfoundrequestlistener,
+ upgradeListener = notfoundupgradelistener
+) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -28,14 +32,16 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
+ onconnection.forEach((listeners) =>
+ Reflect.apply(listeners, serverspdy, [socket])
+ );
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
let ishttp = false;
let istls = false;
const data = socket.read(1);
@@ -43,17 +49,14 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
istls = true;
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
ishttp = true;
- }
- else {
+ } else {
socket.destroy();
}
if (ishttp) {
diff --git a/lib/index.ts b/lib/index.ts
index aa2eba1..78c9bd3 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -9,7 +9,7 @@ const notfoundrequestlistener = function (
res: http.ServerResponse
) {
res.statusCode = 404;
- res.write(404);
+ res.write("404");
res.end();
};
const notfoundupgradelistener = function (
@@ -52,7 +52,7 @@ function createServer(
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket: net.Socket) {
- onconnection.forEach((listeners:Function) =>
+ onconnection.forEach((listeners: Function) =>
Reflect.apply(listeners, serverspdy, [socket])
);
}
diff --git a/test/test.js b/test/test.js
index 8b411a7..fb4ca78 100755
--- a/test/test.js
+++ b/test/test.js
@@ -1,3 +1,4 @@
import "./one.js";
import "./two.js";
import "./three.js";
+import "./zero.js";
diff --git a/test/three.js b/test/three.js
index bde74df..4937af1 100644
--- a/test/three.js
+++ b/test/three.js
@@ -13,12 +13,10 @@ const server = createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
- console.log(req, res);
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("websocket");
},
function (req, socket, head) {
- console.log(req, head);
socket.write(
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
"Upgrade: WebSocket\r\n" +
diff --git a/test/zero.js b/test/zero.js
new file mode 100644
index 0000000..ab762f8
--- /dev/null
+++ b/test/zero.js
@@ -0,0 +1,15 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 8998;
+import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+createServer({
+ key: fs.readFileSync(path.join(__dirname, "server.key")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+}).listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
From 7d102db81ea686a1dd4f2d27dadaa183b1e46f3b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:12:29 +0800
Subject: [PATCH 033/125] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ws?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 4 +++-
yarn.lock | 12 ++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/package.json b/package.json
index f41e69a..08d1332 100644
--- a/package.json
+++ b/package.json
@@ -26,8 +26,10 @@
"@types/spdy": "^3.4.4"
},
"devDependencies": {
- "spdy": "^4.0.2",
+ "@types/ws": "^7.2.4",
+ "ws": "^7.2.3",
"prettier": "^2.0.4",
+ "spdy": "^4.0.2",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
diff --git a/yarn.lock b/yarn.lock
index 830dfb9..55547ed 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -14,6 +14,13 @@
dependencies:
"@types/node" "*"
+"@types/ws@^7.2.4":
+ version "7.2.4"
+ resolved "https://registry.npmjs.org/@types/ws/-/ws-7.2.4.tgz#b3859f7b9c243b220efac9716ec42c716a72969d"
+ integrity sha512-9S6Ask71vujkVyeEXKxjBSUV8ZUB0mjL5la4IncBoheu04bDaYyUKErh1BQcY9+WzOUOiKqz/OnpJHYckbMfNg==
+ dependencies:
+ "@types/node" "*"
+
core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -181,3 +188,8 @@ wbuf@^1.1.0, wbuf@^1.7.3:
integrity sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==
dependencies:
minimalistic-assert "^1.0.0"
+
+ws@^7.2.3:
+ version "7.2.3"
+ resolved "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46"
+ integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==
From a733ac32c6d7388e36ddd462d4c02adc7539fc7d Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:19:20 +0800
Subject: [PATCH 034/125] Update three.js
---
test/three.js | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/test/three.js b/test/three.js
index 4937af1..ef0623e 100644
--- a/test/three.js
+++ b/test/three.js
@@ -4,7 +4,14 @@ const port = 8999;
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
-
+import ws from "ws";
+const wsServer = new ws.Server({ noServer: true });
+wsServer.on("connection", (socket, req) => {
+ socket.send(JSON.stringify(req.headers));
+ socket.send(
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
+ );
+});
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
@@ -17,14 +24,9 @@ const server = createServer(
res.end("websocket");
},
function (req, socket, head) {
- socket.write(
- "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
- "Upgrade: WebSocket\r\n" +
- "Connection: Upgrade\r\n" +
- "\r\n"
- );
-
- socket.pipe(socket);
+ wsServer.handleUpgrade(req, socket, head, function done(ws) {
+ wsServer.emit("connection", ws, req);
+ });
}
);
From bf1d96a2adf8e294347f4b1105b2cd2feb87749f Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:21:22 +0800
Subject: [PATCH 035/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 10 +---------
lib/index.js | 21 +++++++++------------
lib/index.ts | 2 +-
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 7e60238..4db2b9d 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -3,13 +3,5 @@ import http from "http";
import https from "https";
import net from "net";
declare type ServerOptions = https.ServerOptions;
-declare function createServer(
- config: ServerOptions,
- requestListener?: http.RequestListener,
- upgradeListener?: (
- req: http.IncomingMessage,
- socket: net.Socket,
- head: Buffer
- ) => void
-): any;
+declare function createServer(config: ServerOptions, requestListener?: http.RequestListener, upgradeListener?: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 88c4f89..f275491 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,11 +9,7 @@ const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(
- config,
- requestListener = notfoundrequestlistener,
- upgradeListener = notfoundupgradelistener
-) {
+function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -32,16 +28,14 @@ function createServer(
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) =>
- Reflect.apply(listeners, serverspdy, [socket])
- );
+ onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
let ishttp = false;
let istls = false;
const data = socket.read(1);
@@ -49,14 +43,17 @@ function createServer(
socket.once("readable", () => {
connectionListener(socket);
});
- } else {
+ }
+ else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
istls = true;
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
ishttp = true;
- } else {
+ }
+ else {
socket.destroy();
}
if (ishttp) {
diff --git a/lib/index.ts b/lib/index.ts
index 78c9bd3..5934178 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -28,7 +28,7 @@ function createServer(
socket: net.Socket,
head: Buffer
) => void = notfoundupgradelistener
-) {
+): https.Server {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
From f971bc7b3067f31ad735582c14a5c84528507451 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:25:08 +0800
Subject: [PATCH 036/125] Update README.md
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index cb22e4b..e8c080e 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,10 @@ yarn add spdy @masx200/http-https-spdy-http2-polyglot
# Examples
+- Websocket usage
+
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/three.js
+
- Simple usage:
```javascript
From 6a8e2dc0dfe3b3ec624270445a2949f314342753 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:28:52 +0800
Subject: [PATCH 037/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B?=
=?UTF-8?q?=E5=A3=B0=E6=98=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
lib/index.d.ts | 6 ++++--
lib/index.ts | 17 +++++++++--------
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index e8c080e..4c59a85 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ httpolyglot
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
- res.writeHead(301, { Location: tourl.href });
+ res.writeHead(302, { Location: tourl.href });
return res.end();
} else {
res.writeHead(200, { "Content-Type": "text/plain" });
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 4db2b9d..5f111bd 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,6 +2,8 @@
import http from "http";
import https from "https";
import net from "net";
-declare type ServerOptions = https.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener?: http.RequestListener, upgradeListener?: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void): https.Server;
+export declare type RequestListener = http.RequestListener;
+export declare type UpgradeListener = (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
+export declare type ServerOptions = https.ServerOptions;
+declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index 5934178..2afb146 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -2,8 +2,13 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-
-type ServerOptions = https.ServerOptions;
+export type RequestListener = http.RequestListener;
+export type UpgradeListener = (
+ req: http.IncomingMessage,
+ socket: net.Socket,
+ head: Buffer
+) => void;
+export type ServerOptions = https.ServerOptions;
const notfoundrequestlistener = function (
req: http.IncomingMessage,
res: http.ServerResponse
@@ -22,12 +27,8 @@ const notfoundupgradelistener = function (
};
function createServer(
config: ServerOptions,
- requestListener: http.RequestListener = notfoundrequestlistener,
- upgradeListener: (
- req: http.IncomingMessage,
- socket: net.Socket,
- head: Buffer
- ) => void = notfoundupgradelistener
+ requestListener: RequestListener = notfoundrequestlistener,
+ upgradeListener: UpgradeListener = notfoundupgradelistener
): https.Server {
if (!(typeof config === "object")) {
throw new Error("options are required!");
From 9dabbdf19023a30fa12cf9e4b3fd9771b5fc73b4 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:32:33 +0800
Subject: [PATCH 038/125] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/one.js | 1 +
test/three.js | 1 +
2 files changed, 2 insertions(+)
diff --git a/test/one.js b/test/one.js
index 1bdc674..36fe85c 100644
--- a/test/one.js
+++ b/test/one.js
@@ -14,6 +14,7 @@ createServer(
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
+ res.write("alpnProtocol", req.socket.alpnProtocol + " Connection!");
res.end(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
diff --git a/test/three.js b/test/three.js
index ef0623e..6e71e6e 100644
--- a/test/three.js
+++ b/test/three.js
@@ -21,6 +21,7 @@ const server = createServer(
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
+
res.end("websocket");
},
function (req, socket, head) {
From bb7cd5743b4ff05fb201a4174e4d30a8ae24b70e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:35:34 +0800
Subject: [PATCH 039/125] Update one.js
---
test/one.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/one.js b/test/one.js
index 36fe85c..34727f2 100644
--- a/test/one.js
+++ b/test/one.js
@@ -14,7 +14,7 @@ createServer(
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
- res.write("alpnProtocol", req.socket.alpnProtocol + " Connection!");
+ res.write("alpnProtocol:" + req.socket.alpnProtocol + " Connection!\n");
res.end(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
From eea01e41fd9be574bb236dedde57e861ac5edcba Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:40:46 +0800
Subject: [PATCH 040/125] Update one.js
---
test/one.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/one.js b/test/one.js
index 34727f2..b697a08 100644
--- a/test/one.js
+++ b/test/one.js
@@ -13,8 +13,10 @@ createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
+ console.log(req.socket.alpnProtocol);
+
res.writeHead(200, { "Content-Type": "text/plain" });
- res.write("alpnProtocol:" + req.socket.alpnProtocol + " Connection!\n");
+ res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
res.end(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
From d698337d3df7c1f6b01d80726e680e9781e6c566 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Sun, 19 Apr 2020 23:45:08 +0800
Subject: [PATCH 041/125] Update one.js
---
test/one.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/test/one.js b/test/one.js
index b697a08..1dc0ed1 100644
--- a/test/one.js
+++ b/test/one.js
@@ -12,14 +12,17 @@ createServer(
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
- function (req, res) {
- console.log(req.socket.alpnProtocol);
+ async function (req, res) {
+ // console.log(req.socket.alpnProtocol);
res.writeHead(200, { "Content-Type": "text/plain" });
- res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
- res.end(
- ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
+ res.write(
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!\n"
);
+ res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
+ res.end()
+ res.destroy()
+
}
).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
From 16e41cc9671c79c93832ad7e85856ad436f88352 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 00:05:21 +0800
Subject: [PATCH 042/125] Update index.ts
---
lib/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/index.ts b/lib/index.ts
index 2afb146..57113e1 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -14,7 +14,7 @@ const notfoundrequestlistener = function (
res: http.ServerResponse
) {
res.statusCode = 404;
- res.write("404");
+
res.end();
};
const notfoundupgradelistener = function (
From b5c4220fbd870ea6921ed1db3b7af8ad7c9a00aa Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 07:34:41 +0800
Subject: [PATCH 043/125] Update index.ts
---
lib/index.ts | 64 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 42 insertions(+), 22 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 57113e1..e8c9446 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -2,24 +2,40 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-export type RequestListener = http.RequestListener;
+import tls from "tls"
+
+
+
+
+export interface ServerRequest extends ServerRequest{
+
+socket:Socket
+}
+
+export interface ServerResponse extends ServerResponse{
+
+socket:Socket
+
+}
+export type Socket=tls.TLSSocket|net.Socket
+export type RequestListener = (req:ServerRequest,res:ServerResponse)=>void;
export type UpgradeListener = (
- req: http.IncomingMessage,
- socket: net.Socket,
+ req: ServerRequest,
+ socket:Socket,
head: Buffer
) => void;
export type ServerOptions = https.ServerOptions;
const notfoundrequestlistener = function (
- req: http.IncomingMessage,
- res: http.ServerResponse
+ req: ServerRequest,
+ res: ServerResponse
) {
res.statusCode = 404;
res.end();
};
const notfoundupgradelistener = function (
- req: http.IncomingMessage,
- socket: net.Socket,
+ req: ServerRequest,
+ socket:Socket,
head: Buffer
) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
@@ -45,28 +61,28 @@ function createServer(
});
serverhttp.addListener(
"upgrade",
- (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
+ (req: ServerRequest, socket:Socket, head: Buffer) => {
serverspdy.emit("upgrade", req, socket, head);
}
);
serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
- function handletls(socket: net.Socket) {
+ function handletls(socket:net.Socket) {
onconnection.forEach((listeners: Function) =>
Reflect.apply(listeners, serverspdy, [socket])
);
}
- function handlehttp(socket: net.Socket) {
+ function handlehttp(socket:net.Socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
- function connectionListener(socket: net.Socket) {
+ function connectionListener(socket:net.Socket) {
socket.on("error", function onError() {});
- let ishttp = false;
- let istls = false;
+ // let ishttp = false;
+ // let istls = false;
const data = socket.read(1);
/* https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js */
@@ -78,20 +94,24 @@ function createServer(
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
- istls = true;
+
+ handletls(socket);
+ // istls = true;
} else if (32 < firstByte && firstByte < 127) {
- ishttp = true;
+ // ishttp = true;
+
+ handlehttp(socket);
} else {
socket.destroy();
}
- if (ishttp) {
- handlehttp(socket);
- }
- if (istls) {
- handletls(socket);
- }
+ // if (ishttp) {
+
+ // }
+ // if (istls) {
+
+ // }
}
- /* 测试发现不能使用on data事件,会收不到响应 */
+ /* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
return serverspdy;
From 094b4e840cf82f515334eedf63b0dd7e0ae14bb0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 08:38:49 +0800
Subject: [PATCH 044/125] Update three.js
---
test/three.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/three.js b/test/three.js
index 6e71e6e..e59534d 100644
--- a/test/three.js
+++ b/test/three.js
@@ -6,9 +6,9 @@ import { fileURLToPath } from "url";
import { dirname } from "path";
import ws from "ws";
const wsServer = new ws.Server({ noServer: true });
-wsServer.on("connection", (socket, req) => {
- socket.send(JSON.stringify(req.headers));
- socket.send(
+wsServer.on("connection", (websocket, req) => {
+ websocket.send(JSON.stringify(req.headers));
+ websocket.send(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
});
From 600ad76ea880e8271acc304b00503865f59c6a8a Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 09:11:30 +0800
Subject: [PATCH 045/125] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 12 ++++++++--
lib/index.js | 13 ++---------
lib/index.ts | 61 ++++++++++++++++++++++----------------------------
test/one.js | 7 +++---
test/three.js | 2 +-
5 files changed, 43 insertions(+), 52 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 5f111bd..3eefc3f 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,8 +2,16 @@
import http from "http";
import https from "https";
import net from "net";
-export declare type RequestListener = http.RequestListener;
-export declare type UpgradeListener = (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
+import tls from "tls";
+export interface ServerRequest extends http.IncomingMessage {
+ socket: Socket;
+}
+export interface ServerResponse extends http.ServerResponse {
+ socket: Socket;
+}
+export declare type Socket = tls.TLSSocket | net.Socket;
+export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
+export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
export declare type ServerOptions = https.ServerOptions;
declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index f275491..5a4f52f 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,7 +2,6 @@ import http from "http";
import spdy from "spdy";
const notfoundrequestlistener = function (req, res) {
res.statusCode = 404;
- res.write("404");
res.end();
};
const notfoundupgradelistener = function (req, socket, head) {
@@ -36,8 +35,6 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
socket.on("error", function onError() { });
- let ishttp = false;
- let istls = false;
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
@@ -48,20 +45,14 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
- istls = true;
+ handletls(socket);
}
else if (32 < firstByte && firstByte < 127) {
- ishttp = true;
+ handlehttp(socket);
}
else {
socket.destroy();
}
- if (ishttp) {
- handlehttp(socket);
- }
- if (istls) {
- handletls(socket);
- }
}
}
return serverspdy;
diff --git a/lib/index.ts b/lib/index.ts
index e8c9446..32b4d9a 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -2,26 +2,20 @@ import http from "http";
import https from "https";
import net from "net";
import spdy from "spdy";
-import tls from "tls"
+import tls from "tls";
-
-
-
-export interface ServerRequest extends ServerRequest{
-
-socket:Socket
+export interface ServerRequest extends http.IncomingMessage {
+ socket: Socket;
}
-export interface ServerResponse extends ServerResponse{
-
-socket:Socket
-
+export interface ServerResponse extends http.ServerResponse {
+ socket: Socket;
}
-export type Socket=tls.TLSSocket|net.Socket
-export type RequestListener = (req:ServerRequest,res:ServerResponse)=>void;
+export type Socket = tls.TLSSocket | net.Socket;
+export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
export type UpgradeListener = (
req: ServerRequest,
- socket:Socket,
+ socket: Socket,
head: Buffer
) => void;
export type ServerOptions = https.ServerOptions;
@@ -30,12 +24,12 @@ const notfoundrequestlistener = function (
res: ServerResponse
) {
res.statusCode = 404;
-
+
res.end();
};
const notfoundupgradelistener = function (
req: ServerRequest,
- socket:Socket,
+ socket: Socket,
head: Buffer
) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
@@ -61,28 +55,28 @@ function createServer(
});
serverhttp.addListener(
"upgrade",
- (req: ServerRequest, socket:Socket, head: Buffer) => {
+ (req: ServerRequest, socket: Socket, head: Buffer) => {
serverspdy.emit("upgrade", req, socket, head);
}
);
serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
- function handletls(socket:net.Socket) {
+ function handletls(socket: net.Socket) {
onconnection.forEach((listeners: Function) =>
Reflect.apply(listeners, serverspdy, [socket])
);
}
- function handlehttp(socket:net.Socket) {
+ function handlehttp(socket: net.Socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
- function connectionListener(socket:net.Socket) {
+ function connectionListener(socket: net.Socket) {
socket.on("error", function onError() {});
- // let ishttp = false;
- // let istls = false;
+ // let ishttp = false;
+ // let istls = false;
const data = socket.read(1);
/* https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js */
@@ -94,22 +88,21 @@ function createServer(
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
-
- handletls(socket);
- // istls = true;
+ handletls(socket);
+ // istls = true;
} else if (32 < firstByte && firstByte < 127) {
- // ishttp = true;
-
- handlehttp(socket);
+ // ishttp = true;
+
+ handlehttp(socket);
} else {
socket.destroy();
}
- // if (ishttp) {
-
- // }
- // if (istls) {
-
- // }
+ // if (ishttp) {
+
+ // }
+ // if (istls) {
+
+ // }
}
/* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
diff --git a/test/one.js b/test/one.js
index 1dc0ed1..d39d8c2 100644
--- a/test/one.js
+++ b/test/one.js
@@ -12,7 +12,7 @@ createServer(
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
- async function (req, res) {
+ async function (req, res) {
// console.log(req.socket.alpnProtocol);
res.writeHead(200, { "Content-Type": "text/plain" });
@@ -20,9 +20,8 @@ createServer(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!\n"
);
res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
- res.end()
- res.destroy()
-
+ res.end();
+ res.destroy();
}
).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
diff --git a/test/three.js b/test/three.js
index e59534d..ba80bbd 100644
--- a/test/three.js
+++ b/test/three.js
@@ -21,7 +21,7 @@ const server = createServer(
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
-
+
res.end("websocket");
},
function (req, socket, head) {
From b690d5e0478b20f5b9c184e4830f09c7d2799061 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 09:13:39 +0800
Subject: [PATCH 046/125] Update index.ts
---
lib/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/index.ts b/lib/index.ts
index 32b4d9a..b718e64 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -18,7 +18,7 @@ export type UpgradeListener = (
socket: Socket,
head: Buffer
) => void;
-export type ServerOptions = https.ServerOptions;
+export type ServerOptions = spdy.ServerOptions;
const notfoundrequestlistener = function (
req: ServerRequest,
res: ServerResponse
From 609b3159b64aed85cec0e2a9c9008fb9043e553f Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 09:21:55 +0800
Subject: [PATCH 047/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitattributes | 5 +++++
lib/index.d.ts | 5 +++--
lib/index.ts | 2 +-
test/one.d.ts | 1 -
test/two.d.ts | 1 -
test/two.js | 8 ++++----
6 files changed, 13 insertions(+), 9 deletions(-)
create mode 100644 .gitattributes
delete mode 100644 test/one.d.ts
delete mode 100644 test/two.d.ts
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..a2a0a67
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+*.js linguist-language=Typescript
+*.css linguist-language=Typescript
+*.html linguist-language=Typescript
+*.jsx linguist-language=Typescript
+*.ts linguist-language=Typescript
\ No newline at end of file
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 3eefc3f..6268b4e 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -2,6 +2,7 @@
import http from "http";
import https from "https";
import net from "net";
+import spdy from "spdy";
import tls from "tls";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
@@ -9,9 +10,9 @@ export interface ServerRequest extends http.IncomingMessage {
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
}
-export declare type Socket = tls.TLSSocket | net.Socket;
+export declare type Socket = Partial & net.Socket;
export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
-export declare type ServerOptions = https.ServerOptions;
+export declare type ServerOptions = spdy.ServerOptions;
declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index b718e64..2b5b231 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -11,7 +11,7 @@ export interface ServerRequest extends http.IncomingMessage {
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
}
-export type Socket = tls.TLSSocket | net.Socket;
+export type Socket = Partial & net.Socket;
export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
export type UpgradeListener = (
req: ServerRequest,
diff --git a/test/one.d.ts b/test/one.d.ts
deleted file mode 100644
index cb0ff5c..0000000
--- a/test/one.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-export {};
diff --git a/test/two.d.ts b/test/two.d.ts
deleted file mode 100644
index cb0ff5c..0000000
--- a/test/two.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-export {};
diff --git a/test/two.js b/test/two.js
index dbca2f9..ac438b3 100644
--- a/test/two.js
+++ b/test/two.js
@@ -13,16 +13,16 @@ createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
- if (!("encrypted" in req.socket)) {
+ if ("encrypted" in req.socket) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
+ } else {
const host = req.headers["host"];
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
res.writeHead(302, { Location: tourl.href });
return res.end();
- } else {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end("Welcome, HTTPS user!");
}
}
).listen(port, "localhost", function () {
From 093613eea7dbbea1c271d798942541c1eed65561 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 09:25:16 +0800
Subject: [PATCH 048/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 8 ++++++++
lib/index.d.ts | 17 ++++++++++++++---
lib/index.js | 21 ++++++++++++---------
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index 4c59a85..fd99fd5 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,14 @@ https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/lib/index.
- **createServer** - Creates and returns a new Server instance.
+```ts
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): https.Server;
+```
+
# How it Works
https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 6268b4e..24823e4 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -11,8 +11,19 @@ export interface ServerResponse extends http.ServerResponse {
socket: Socket;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
-export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
export declare type ServerOptions = spdy.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 5a4f52f..697261f 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -8,7 +8,11 @@ const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
+function createServer(
+ config,
+ requestListener = notfoundrequestlistener,
+ upgradeListener = notfoundupgradelistener
+) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -27,30 +31,29 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
+ onconnection.forEach((listeners) =>
+ Reflect.apply(listeners, serverspdy, [socket])
+ );
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- }
- else {
+ } else {
socket.destroy();
}
}
From e0c209d11710113aad815fa283fbea2893d660f1 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:03:37 +0800
Subject: [PATCH 049/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 7 +++++++
lib/index.ts | 8 +++++++-
package.json | 1 +
test/one.js | 3 +--
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 24823e4..e7c74e3 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -7,8 +7,15 @@ import tls from "tls";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
+interface PushOptions {
+ status?: number;
+ method?: string;
+ request?: any;
+ response?: any;
+}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
+ push?: (filename: string, options: PushOptions) => any;
}
export declare type Socket = Partial & net.Socket;
export declare type RequestListener = (
diff --git a/lib/index.ts b/lib/index.ts
index 2b5b231..04272fe 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -7,9 +7,15 @@ import tls from "tls";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
-
+interface PushOptions {
+ status?: number;
+ method?: string;
+ request?: any;
+ response?: any;
+}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
+ push?: (filename: string, options: PushOptions) => any;
}
export type Socket = Partial & net.Socket;
export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
diff --git a/package.json b/package.json
index 08d1332..547c61f 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"version": "1.0.0",
"main": "./lib/index.js",
"scripts": {
+ "debug": "node --inspect test/test.js",
"build": "tsc",
"test": "node test/test.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
diff --git a/test/one.js b/test/one.js
index d39d8c2..c6fd42d 100644
--- a/test/one.js
+++ b/test/one.js
@@ -13,13 +13,12 @@ createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
async function (req, res) {
- // console.log(req.socket.alpnProtocol);
-
res.writeHead(200, { "Content-Type": "text/plain" });
res.write(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!\n"
);
res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
+
res.end();
res.destroy();
}
From f978a72cc0aa21b864013f87d9fdc1122d5eb568 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:27:44 +0800
Subject: [PATCH 050/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
lib/index.d.ts | 17 +++-----------
lib/index.js | 22 +++++++++----------
lib/index.ts | 2 +-
package.json | 2 +-
test/{zero.js => notfound.js} | 0
test/push.js | 39 +++++++++++++++++++++++++++++++++
test/{two.js => redirect.js} | 0
test/{one.js => simple.js} | 3 +--
test/test.js | 9 ++++----
test/{three.js => websocket.js} | 0
11 files changed, 61 insertions(+), 35 deletions(-)
rename test/{zero.js => notfound.js} (100%)
create mode 100644 test/push.js
rename test/{two.js => redirect.js} (100%)
rename test/{one.js => simple.js} (90%)
rename test/{three.js => websocket.js} (100%)
diff --git a/README.md b/README.md
index fd99fd5..6605acc 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Serve http and https and spdy and http2 connections over the same port with node
# Requirements
-- [node.js](http://nodejs.org/) -- v8.0.0 or newer
+- [node.js](http://nodejs.org/) -- v13.0.0 or newer
# Install
diff --git a/lib/index.d.ts b/lib/index.d.ts
index e7c74e3..1182bb6 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -18,19 +18,8 @@ export interface ServerResponse extends http.ServerResponse {
push?: (filename: string, options: PushOptions) => any;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (
- req: ServerRequest,
- res: ServerResponse
-) => void;
-export declare type UpgradeListener = (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
+export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
+export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
export declare type ServerOptions = spdy.ServerOptions;
-declare function createServer(
- config: ServerOptions,
- requestListener?: RequestListener,
- upgradeListener?: UpgradeListener
-): https.Server;
+declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 697261f..2729ef4 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,17 +2,14 @@ import http from "http";
import spdy from "spdy";
const notfoundrequestlistener = function (req, res) {
res.statusCode = 404;
+ res.write("404");
res.end();
};
const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(
- config,
- requestListener = notfoundrequestlistener,
- upgradeListener = notfoundupgradelistener
-) {
+function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -31,29 +28,30 @@ function createServer(
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) =>
- Reflect.apply(listeners, serverspdy, [socket])
- );
+ onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- } else {
+ }
+ else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- } else {
+ }
+ else {
socket.destroy();
}
}
diff --git a/lib/index.ts b/lib/index.ts
index 04272fe..920d430 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -30,7 +30,7 @@ const notfoundrequestlistener = function (
res: ServerResponse
) {
res.statusCode = 404;
-
+ res.write("404");
res.end();
};
const notfoundupgradelistener = function (
diff --git a/package.json b/package.json
index 547c61f..ee8db5e 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
- "node": ">=8.0.0"
+ "node": ">=13.0.0"
},
"peerDependencies": {
"spdy": "^4.0.2"
diff --git a/test/zero.js b/test/notfound.js
similarity index 100%
rename from test/zero.js
rename to test/notfound.js
diff --git a/test/push.js b/test/push.js
new file mode 100644
index 0000000..538c7af
--- /dev/null
+++ b/test/push.js
@@ -0,0 +1,39 @@
+import { createServer } from "../lib/index.js";
+import fs from "fs";
+const port = 9002;
+import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+const server = createServer(
+ {
+ key: fs.readFileSync(path.join(__dirname, "server.key")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ },
+ (req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ if (res.push) {
+ var stream = res.push("/main.js", {
+ status: 200, // optional
+ method: "GET", // optional
+ request: {
+ accept: "*/*",
+ },
+ response: {
+ "content-type": "application/javascript",
+ },
+ });
+ stream.on("error", function (e) {
+ console.log(e);
+ });
+ stream.end('alert("hello from push stream!");');
+ }
+
+ res.end('push');
+ }
+);
+server.listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
diff --git a/test/two.js b/test/redirect.js
similarity index 100%
rename from test/two.js
rename to test/redirect.js
diff --git a/test/one.js b/test/simple.js
similarity index 90%
rename from test/one.js
rename to test/simple.js
index c6fd42d..cd2a195 100644
--- a/test/one.js
+++ b/test/simple.js
@@ -13,14 +13,13 @@ createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
async function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
+ res.writeHead(200, { "Content-Type": "text/html" });
res.write(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!\n"
);
res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
res.end();
- res.destroy();
}
).listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
diff --git a/test/test.js b/test/test.js
index fb4ca78..3b08abe 100755
--- a/test/test.js
+++ b/test/test.js
@@ -1,4 +1,5 @@
-import "./one.js";
-import "./two.js";
-import "./three.js";
-import "./zero.js";
+import "./notfound.js";
+import "./simple.js";
+import "./push.js";
+import "./redirect.js";
+import "./websocket.js";
diff --git a/test/three.js b/test/websocket.js
similarity index 100%
rename from test/three.js
rename to test/websocket.js
From 109ced8332921ab82bde1a3f1687f70a99ec690e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:35:50 +0800
Subject: [PATCH 051/125] =?UTF-8?q?=E4=BC=98=E5=8C=96push=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 14 ++++++++++----
lib/index.d.ts | 17 ++++++++++++++---
lib/index.js | 21 ++++++++++++---------
test/push.js | 44 ++++++++++++++++++++++++++------------------
4 files changed, 62 insertions(+), 34 deletions(-)
diff --git a/README.md b/README.md
index 6605acc..52b7cab 100644
--- a/README.md
+++ b/README.md
@@ -14,11 +14,17 @@ yarn add spdy @masx200/http-https-spdy-http2-polyglot
# Examples
-- Websocket usage
-https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/three.js
+- http2 server push
-- Simple usage:
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.js
+
+
+- Websocket
+
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
+
+- Simple
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
@@ -42,7 +48,7 @@ httpolyglot
});
```
-- Simple redirect of all http connections to https:
+- redirect all http connections to https:
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 1182bb6..e7c74e3 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -18,8 +18,19 @@ export interface ServerResponse extends http.ServerResponse {
push?: (filename: string, options: PushOptions) => any;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
-export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
export declare type ServerOptions = spdy.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 2729ef4..54c73b3 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,7 +9,11 @@ const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
+function createServer(
+ config,
+ requestListener = notfoundrequestlistener,
+ upgradeListener = notfoundupgradelistener
+) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -28,30 +32,29 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
+ onconnection.forEach((listeners) =>
+ Reflect.apply(listeners, serverspdy, [socket])
+ );
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- }
- else {
+ } else {
socket.destroy();
}
}
diff --git a/test/push.js b/test/push.js
index 538c7af..620d690 100644
--- a/test/push.js
+++ b/test/push.js
@@ -13,25 +13,33 @@ const server = createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
(req, res) => {
- res.writeHead(200, { "Content-Type": "text/html" });
- if (res.push) {
- var stream = res.push("/main.js", {
- status: 200, // optional
- method: "GET", // optional
- request: {
- accept: "*/*",
- },
- response: {
- "content-type": "application/javascript",
- },
- });
- stream.on("error", function (e) {
- console.log(e);
- });
- stream.end('alert("hello from push stream!");');
- }
+ if (req.url == "/main.js") {
+ res.statusCode = 200;
+ res.setHeader("content-type", "application/javascript");
+ res.end('alert("not from push stream")');
+ return;
+ } else {
+ res.writeHead(200, { "Content-Type": "text/html" });
+
+ if (res.push) {
+ var stream = res.push("/main.js", {
+ status: 200, // optional
+ method: "GET", // optional
+ request: {
+ accept: "*/*",
+ },
+ response: {
+ "content-type": "application/javascript",
+ },
+ });
+ stream.on("error", function (e) {
+ console.log(e);
+ });
+ stream.end('alert("hello from push stream!");');
+ }
- res.end('push');
+ res.end('push');
+ }
}
);
server.listen(port, "localhost", function () {
From 1c4705cf67d802dcc21890d3301ad56d39b2e67c Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:40:28 +0800
Subject: [PATCH 052/125] Update index.d.ts
---
lib/index.d.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index e7c74e3..cdf095d 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -17,6 +17,7 @@ export interface ServerResponse extends http.ServerResponse {
socket: Socket;
push?: (filename: string, options: PushOptions) => any;
}
+
export declare type Socket = Partial & net.Socket;
export declare type RequestListener = (
req: ServerRequest,
From e78f7198960173effe87f11b1451cf0589ad1d9d Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:46:03 +0800
Subject: [PATCH 053/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B?=
=?UTF-8?q?=E5=A3=B0=E6=98=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 25 +++++++------------------
lib/index.js | 21 +++++++++------------
lib/index.ts | 7 ++++---
3 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index cdf095d..cdebe29 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -4,34 +4,23 @@ import https from "https";
import net from "net";
import spdy from "spdy";
import tls from "tls";
+import stream from "stream";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
interface PushOptions {
status?: number;
method?: string;
- request?: any;
- response?: any;
+ request?: http.OutgoingHttpHeaders;
+ response?: http.OutgoingHttpHeaders;
}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
- push?: (filename: string, options: PushOptions) => any;
+ push?: (filename: string, options: PushOptions) => stream.Writable;
}
-
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (
- req: ServerRequest,
- res: ServerResponse
-) => void;
-export declare type UpgradeListener = (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
+export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
+export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
export declare type ServerOptions = spdy.ServerOptions;
-declare function createServer(
- config: ServerOptions,
- requestListener?: RequestListener,
- upgradeListener?: UpgradeListener
-): https.Server;
+declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 54c73b3..2729ef4 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,11 +9,7 @@ const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(
- config,
- requestListener = notfoundrequestlistener,
- upgradeListener = notfoundupgradelistener
-) {
+function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -32,29 +28,30 @@ function createServer(
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) =>
- Reflect.apply(listeners, serverspdy, [socket])
- );
+ onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() {});
+ socket.on("error", function onError() { });
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- } else {
+ }
+ else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- } else {
+ }
+ else {
socket.destroy();
}
}
diff --git a/lib/index.ts b/lib/index.ts
index 920d430..06f04f3 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -3,6 +3,7 @@ import https from "https";
import net from "net";
import spdy from "spdy";
import tls from "tls";
+import stream from "stream";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
@@ -10,12 +11,12 @@ export interface ServerRequest extends http.IncomingMessage {
interface PushOptions {
status?: number;
method?: string;
- request?: any;
- response?: any;
+ request?: http.OutgoingHttpHeaders;
+ response?: http.OutgoingHttpHeaders;
}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
- push?: (filename: string, options: PushOptions) => any;
+ push?: (filename: string, options: PushOptions) => stream.Writable;
}
export type Socket = Partial & net.Socket;
export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
From 3e20ee7ef0c0812ae395bee33981b11b1dc31cf3 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 10:51:17 +0800
Subject: [PATCH 054/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.d.ts | 2 +-
lib/index.ts | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/index.d.ts b/lib/index.d.ts
index cdebe29..26dae67 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -16,7 +16,7 @@ interface PushOptions {
}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
- push?: (filename: string, options: PushOptions) => stream.Writable;
+ push?: (pathname: string, options: PushOptions) => stream.Writable;
}
export declare type Socket = Partial & net.Socket;
export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
diff --git a/lib/index.ts b/lib/index.ts
index 06f04f3..c02a604 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -16,7 +16,7 @@ interface PushOptions {
}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
- push?: (filename: string, options: PushOptions) => stream.Writable;
+ push?: (pathname: string, options: PushOptions) => stream.Writable;
}
export type Socket = Partial & net.Socket;
export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
From 829a47f404a68c0ef11167bb0274228ceea2e8d5 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:01:45 +0800
Subject: [PATCH 055/125] Update notfound.js
---
test/notfound.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/notfound.js b/test/notfound.js
index ab762f8..cd99806 100644
--- a/test/notfound.js
+++ b/test/notfound.js
@@ -7,9 +7,11 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-createServer({
+const server = createServer({
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
-}).listen(port, "localhost", function () {
+});
+
+server.listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
});
From 65504c42771d014eb1c72545d330cbe1235ed4cd Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:05:44 +0800
Subject: [PATCH 056/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
package.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 52b7cab..702648c 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Serve http and https and spdy and http2 connections over the same port with node
# Requirements
-- [node.js](http://nodejs.org/) -- v13.0.0 or newer
+- [node.js](http://nodejs.org/) -- v12.0.0 or newer
# Install
diff --git a/package.json b/package.json
index ee8db5e..5e35c37 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
- "node": ">=13.0.0"
+ "node": ">=12.0.0"
},
"peerDependencies": {
"spdy": "^4.0.2"
From 1cbf67215a60e6f31b56696080441a31b174be27 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:19:52 +0800
Subject: [PATCH 057/125] =?UTF-8?q?=E8=BD=AC=E5=8F=91http=E4=BA=8B?=
=?UTF-8?q?=E4=BB=B6=E5=88=B0server?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 12 +++++++++---
lib/index.ts | 22 ++++++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 2729ef4..420b86a 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -15,15 +15,21 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
}
const serverhttp = http.createServer(config);
const serverspdy = spdy.createServer(config);
+ serverhttp.addListener("connect", (request, socket, head) => {
+ serverspdy.emit("connect", request, socket, head);
+ });
+ serverhttp.addListener("clientError", (error, socket) => {
+ serverspdy.emit("clientError", error, socket);
+ });
+ serverhttp.addListener("upgrade", (request, socket, head) => {
+ serverspdy.emit("upgrade", request, socket, head);
+ });
serverhttp.removeAllListeners("request");
serverspdy.removeAllListeners("request");
serverspdy.addListener("request", requestListener);
serverhttp.addListener("request", (req, res) => {
serverspdy.emit("request", req, res);
});
- serverhttp.addListener("upgrade", (req, socket, head) => {
- serverspdy.emit("upgrade", req, socket, head);
- });
serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
diff --git a/lib/index.ts b/lib/index.ts
index c02a604..37712e8 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -54,18 +54,28 @@ function createServer(
const serverhttp = http.createServer(config);
//@ts-ignore
const serverspdy = spdy.createServer(config);
+ serverhttp.addListener(
+ "connect",
+ (request: ServerRequest, socket: Socket, head: Buffer) => {
+ serverspdy.emit("connect", request, socket, head);
+ }
+ );
+ serverhttp.addListener("clientError", (error: Error, socket: Socket) => {
+ serverspdy.emit("clientError", error, socket);
+ });
+ serverhttp.addListener(
+ "upgrade",
+ (request: ServerRequest, socket: Socket, head: Buffer) => {
+ serverspdy.emit("upgrade", request, socket, head);
+ }
+ );
serverhttp.removeAllListeners("request");
serverspdy.removeAllListeners("request");
serverspdy.addListener("request", requestListener);
serverhttp.addListener("request", (req, res) => {
serverspdy.emit("request", req, res);
});
- serverhttp.addListener(
- "upgrade",
- (req: ServerRequest, socket: Socket, head: Buffer) => {
- serverspdy.emit("upgrade", req, socket, head);
- }
- );
+
serverspdy.addListener("upgrade", upgradeListener);
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
From b1db1adca94f02a46fac4fe364fc0412b7790f1b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:21:47 +0800
Subject: [PATCH 058/125] Update README.md
---
README.md | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 702648c..6fa9946 100644
--- a/README.md
+++ b/README.md
@@ -14,13 +14,11 @@ yarn add spdy @masx200/http-https-spdy-http2-polyglot
# Examples
-
-- http2 server push
+- http2 server push
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.js
-
-- Websocket
+- Websocket
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
@@ -95,6 +93,10 @@ declare function createServer(
): https.Server;
```
+The requestListener is a function which is automatically added to the 'request' event
+
+The upgradeListener is a function which is automatically added to the 'upgrade' event
+
# How it Works
https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
From b1948bd11f993a4d670998d5c5097b505a320afd Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:23:25 +0800
Subject: [PATCH 059/125] Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 6fa9946..0ec10ec 100644
--- a/README.md
+++ b/README.md
@@ -93,9 +93,9 @@ declare function createServer(
): https.Server;
```
-The requestListener is a function which is automatically added to the 'request' event
+The `requestListener` is a function which is automatically added to the 'request' event
-The upgradeListener is a function which is automatically added to the 'upgrade' event
+The `upgradeListener` is a function which is automatically added to the 'upgrade' event
# How it Works
From 4902f4195e0a5d8328c1f6340d1c59911ded70ef Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:24:38 +0800
Subject: [PATCH 060/125] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 0ec10ec..6a1203e 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
-- Simple
+- Simple Determine if the connection is https.
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
From 591c28b69f5879eea3e52659cb28e0400d2c7958 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:28:57 +0800
Subject: [PATCH 061/125] Update README.md
---
README.md | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6a1203e..0fa49c2 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,20 @@ Serve http and https and spdy and http2 connections over the same port with node
yarn add spdy @masx200/http-https-spdy-http2-polyglot
```
+# Connection protocol judgment
+
+Determine if the connection is tls.
+
+```js
+const istls = "encrypted" in req.socket;
+```
+
+Determine if the connection is http/2.
+
+```js
+const ishttp2 = "h2" === req.socket.alpnProtocol;
+```
+
# Examples
- http2 server push
@@ -22,7 +36,7 @@ https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
-- Simple Determine if the connection is https.
+- Simple Determine if the connection is tls.
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
From 6712f8c8bf9807fa378c05683aaafdb39487493a Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 11:30:32 +0800
Subject: [PATCH 062/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 ++--
lib/index.d.ts | 17 ++++++++++++++---
lib/index.js | 21 ++++++++++++---------
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 0fa49c2..1e37e73 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ yarn add spdy @masx200/http-https-spdy-http2-polyglot
# Connection protocol judgment
-Determine if the connection is tls.
+Determine if the connection is over tls.
```js
const istls = "encrypted" in req.socket;
@@ -36,7 +36,7 @@ https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
-- Simple Determine if the connection is tls.
+- Simple Determine the connection protocol
```javascript
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 26dae67..1e04550 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -19,8 +19,19 @@ export interface ServerResponse extends http.ServerResponse {
push?: (pathname: string, options: PushOptions) => stream.Writable;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
-export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
export declare type ServerOptions = spdy.ServerOptions;
-declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): https.Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): https.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 420b86a..63c2efe 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,7 +9,11 @@ const notfoundupgradelistener = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
-function createServer(config, requestListener = notfoundrequestlistener, upgradeListener = notfoundupgradelistener) {
+function createServer(
+ config,
+ requestListener = notfoundrequestlistener,
+ upgradeListener = notfoundupgradelistener
+) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
@@ -34,30 +38,29 @@ function createServer(config, requestListener = notfoundrequestlistener, upgrade
const onconnection = serverspdy.listeners("connection");
serverspdy.removeAllListeners("connection");
function handletls(socket) {
- onconnection.forEach((listeners) => Reflect.apply(listeners, serverspdy, [socket]));
+ onconnection.forEach((listeners) =>
+ Reflect.apply(listeners, serverspdy, [socket])
+ );
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() { });
+ socket.on("error", function onError() {});
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- }
- else {
+ } else {
socket.destroy();
}
}
From 39ecb18fc1ce0c73b8d301fa1f0ff6927a218e4f Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 13:00:53 +0800
Subject: [PATCH 063/125] Update redirect.js
---
test/redirect.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/redirect.js b/test/redirect.js
index ac438b3..4446335 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -7,7 +7,7 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const port = 9001;
-createServer(
+const server=createServer(
{
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
@@ -25,6 +25,8 @@ createServer(
return res.end();
}
}
-).listen(port, "localhost", function () {
+)
+
+server.listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
});
From cd64180de7a8b27fcd5822803ee163d52a8ba665 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 13:01:31 +0800
Subject: [PATCH 064/125] Update simple.js
---
test/simple.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/simple.js b/test/simple.js
index cd2a195..5527c19 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -7,7 +7,7 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-createServer(
+const server=createServer(
{
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
@@ -21,6 +21,8 @@ createServer(
res.end();
}
-).listen(port, "localhost", function () {
+)
+
+server.listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
});
From a4848e6156c5c7205789e7556750be605a771c79 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 13:10:28 +0800
Subject: [PATCH 065/125] Update package.json
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 5e35c37..e39a2f2 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"scripts": {
"debug": "node --inspect test/test.js",
"build": "tsc",
- "test": "node test/test.js",
+ "test": "node --experimental-modules test/test.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
From 34e3554683a39e45b283a34df3d48830dfb01e0a Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 14:08:45 +0800
Subject: [PATCH 066/125] Update index.ts
---
lib/index.ts | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index 37712e8..2f6d5c9 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -90,8 +90,13 @@ function createServer(
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
- socket.on("error", function onError() {});
-
+ //如果没有error监听器就添加error 监听器
+if(
+!socket.
+listeners("error").length
+){
+socket.on("error", function () {});
+}
// let ishttp = false;
// let istls = false;
From fa27a292ed3ab8e0fa8f21773915e781d659a221 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 14:11:11 +0800
Subject: [PATCH 067/125] Update index.ts
---
lib/index.ts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/index.ts b/lib/index.ts
index 2f6d5c9..fc84068 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -110,6 +110,9 @@ socket.on("error", function () {});
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
+//默认已经是false了
+//// TLS sockets don't allow half open
+ // socket.allowHalfOpen = false;
handletls(socket);
// istls = true;
} else if (32 < firstByte && firstByte < 127) {
From 6602731152d13db8c88486444185e8b1531fd266 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 15:00:27 +0800
Subject: [PATCH 068/125] Update index.ts
---
lib/index.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/index.ts b/lib/index.ts
index fc84068..b78e1d8 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -4,7 +4,7 @@ import net from "net";
import spdy from "spdy";
import tls from "tls";
import stream from "stream";
-
+import {onlyonelistener}from "./onlyonelistener.js"
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
@@ -16,7 +16,7 @@ interface PushOptions {
}
export interface ServerResponse extends http.ServerResponse {
socket: Socket;
- push?: (pathname: string, options: PushOptions) => stream.Writable;
+ push?: (pathname: string, options?: PushOptions) => stream.Writable;
}
export type Socket = Partial & net.Socket;
export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
@@ -132,6 +132,6 @@ socket.on("error", function () {});
/* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
- return serverspdy;
+ return onlyonelistener(serverspdy);
}
export { createServer };
From ac85dfa2e3fd12dc597450f32a62d8bec36c5100 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 15:02:54 +0800
Subject: [PATCH 069/125] Add files via upload
---
lib/onlyonelistener.js | 49 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 lib/onlyonelistener.js
diff --git a/lib/onlyonelistener.js b/lib/onlyonelistener.js
new file mode 100644
index 0000000..2ffbd5b
--- /dev/null
+++ b/lib/onlyonelistener.js
@@ -0,0 +1,49 @@
+import {EventEmitter} from "events"
+import assert from "assert"
+
+const proxykeys=["addListener","on","prependListener]
+export function onlyonelistener(emitter:EventEmitter){
+emitter.setMaxListeners(1)
+return new Proxy(emitter,{
+
+get(target,key){
+
+const value=Reflect.get(target,key)
+if(proxykeys.includes(key)){
+
+
+return new Proxy(value,{
+
+
+
+apply(target, thisArgument, argumentsList){
+ const [eventName,listener]=argumentsList
+ assert(typeof eventName==="string")
+ assert(typeof listener==="function")
+ Reflect.apply(EventEmitter.prototype.removeAllListeners,
+
+thisArgument,argumentsList)
+
+
+
+ return Reflect.apply(target, thisArgument, argumentsList)
+
+
+
+
+}
+
+
+})
+}else{
+
+return value
+}
+
+
+
+
+
+
+}})
+}
\ No newline at end of file
From 21d9277de7add631a424c32eb42c1b24925c3040 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 15:03:23 +0800
Subject: [PATCH 070/125] Rename onlyonelistener.js to onlyonelistener.ts
---
lib/{onlyonelistener.js => onlyonelistener.ts} | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename lib/{onlyonelistener.js => onlyonelistener.ts} (93%)
diff --git a/lib/onlyonelistener.js b/lib/onlyonelistener.ts
similarity index 93%
rename from lib/onlyonelistener.js
rename to lib/onlyonelistener.ts
index 2ffbd5b..2dc04ca 100644
--- a/lib/onlyonelistener.js
+++ b/lib/onlyonelistener.ts
@@ -46,4 +46,4 @@ return value
}})
-}
\ No newline at end of file
+}
From 05058661e35f979fd805f6f154e360d6405e05ac Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 15:04:05 +0800
Subject: [PATCH 071/125] Update onlyonelistener.ts
---
lib/onlyonelistener.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/onlyonelistener.ts b/lib/onlyonelistener.ts
index 2dc04ca..1daf0b0 100644
--- a/lib/onlyonelistener.ts
+++ b/lib/onlyonelistener.ts
@@ -1,7 +1,7 @@
import {EventEmitter} from "events"
import assert from "assert"
-const proxykeys=["addListener","on","prependListener]
+const proxykeys=["addListener","on","prependListener"]
export function onlyonelistener(emitter:EventEmitter){
emitter.setMaxListeners(1)
return new Proxy(emitter,{
From f6ff9e6d61450a5b4b09926b0d1023a3f2b719a9 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 17:08:40 +0800
Subject: [PATCH 072/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96=E6=A0=BC=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.ts | 30 +++++++++-----------------
lib/onlyonelistener.ts | 49 ------------------------------------------
test/redirect.js | 4 ++--
test/simple.js | 4 ++--
4 files changed, 14 insertions(+), 73 deletions(-)
delete mode 100644 lib/onlyonelistener.ts
diff --git a/lib/index.ts b/lib/index.ts
index b78e1d8..235d44e 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -4,7 +4,7 @@ import net from "net";
import spdy from "spdy";
import tls from "tls";
import stream from "stream";
-import {onlyonelistener}from "./onlyonelistener.js"
+
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
@@ -54,15 +54,7 @@ function createServer(
const serverhttp = http.createServer(config);
//@ts-ignore
const serverspdy = spdy.createServer(config);
- serverhttp.addListener(
- "connect",
- (request: ServerRequest, socket: Socket, head: Buffer) => {
- serverspdy.emit("connect", request, socket, head);
- }
- );
- serverhttp.addListener("clientError", (error: Error, socket: Socket) => {
- serverspdy.emit("clientError", error, socket);
- });
+
serverhttp.addListener(
"upgrade",
(request: ServerRequest, socket: Socket, head: Buffer) => {
@@ -90,13 +82,11 @@ function createServer(
serverspdy.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
+ socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
-if(
-!socket.
-listeners("error").length
-){
-socket.on("error", function () {});
-}
+ if (!socket.listeners("error").length) {
+ socket.on("error", function () {});
+ }
// let ishttp = false;
// let istls = false;
@@ -110,9 +100,9 @@ socket.on("error", function () {});
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
-//默认已经是false了
-//// TLS sockets don't allow half open
- // socket.allowHalfOpen = false;
+ //默认已经是false了
+ //// TLS sockets don't allow half open
+ // socket.allowHalfOpen = false;
handletls(socket);
// istls = true;
} else if (32 < firstByte && firstByte < 127) {
@@ -132,6 +122,6 @@ socket.on("error", function () {});
/* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
- return onlyonelistener(serverspdy);
+ return serverspdy;
}
export { createServer };
diff --git a/lib/onlyonelistener.ts b/lib/onlyonelistener.ts
deleted file mode 100644
index 1daf0b0..0000000
--- a/lib/onlyonelistener.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import {EventEmitter} from "events"
-import assert from "assert"
-
-const proxykeys=["addListener","on","prependListener"]
-export function onlyonelistener(emitter:EventEmitter){
-emitter.setMaxListeners(1)
-return new Proxy(emitter,{
-
-get(target,key){
-
-const value=Reflect.get(target,key)
-if(proxykeys.includes(key)){
-
-
-return new Proxy(value,{
-
-
-
-apply(target, thisArgument, argumentsList){
- const [eventName,listener]=argumentsList
- assert(typeof eventName==="string")
- assert(typeof listener==="function")
- Reflect.apply(EventEmitter.prototype.removeAllListeners,
-
-thisArgument,argumentsList)
-
-
-
- return Reflect.apply(target, thisArgument, argumentsList)
-
-
-
-
-}
-
-
-})
-}else{
-
-return value
-}
-
-
-
-
-
-
-}})
-}
diff --git a/test/redirect.js b/test/redirect.js
index 4446335..9703a40 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -7,7 +7,7 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const port = 9001;
-const server=createServer(
+const server = createServer(
{
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
@@ -25,7 +25,7 @@ const server=createServer(
return res.end();
}
}
-)
+);
server.listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
diff --git a/test/simple.js b/test/simple.js
index 5527c19..def08d4 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -7,7 +7,7 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-const server=createServer(
+const server = createServer(
{
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
@@ -21,7 +21,7 @@ const server=createServer(
res.end();
}
-)
+);
server.listen(port, "localhost", function () {
console.log("httpolyglot server listening on port " + port);
From 688957b1780361e0c2ba0181cd7dcbf72760e761 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 17:26:17 +0800
Subject: [PATCH 073/125] =?UTF-8?q?=E7=AE=80=E5=8C=96=E7=BB=93=E6=9E=84?=
=?UTF-8?q?=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/declaration.d.ts | 46 ++++++++++++++++++++
lib/declaration.js | 9 ++++
lib/declaration.ts | 48 +++++++++++++++++++++
lib/index.d.ts | 36 +++-------------
lib/index.js | 47 +++++++--------------
lib/index.ts | 99 ++++++++++++++++----------------------------
test/websocket.js | 2 +-
7 files changed, 161 insertions(+), 126 deletions(-)
create mode 100644 lib/declaration.d.ts
create mode 100644 lib/declaration.js
create mode 100644 lib/declaration.ts
diff --git a/lib/declaration.d.ts b/lib/declaration.d.ts
new file mode 100644
index 0000000..c59f793
--- /dev/null
+++ b/lib/declaration.d.ts
@@ -0,0 +1,46 @@
+///
+import http from "http";
+import net from "net";
+import spdy from "spdy";
+import tls from "tls";
+import stream from "stream";
+import https from "https";
+export interface ServerRequest extends http.IncomingMessage {
+ socket: Socket;
+}
+interface PushOptions {
+ status?: number;
+ method?: string;
+ request?: http.OutgoingHttpHeaders;
+ response?: http.OutgoingHttpHeaders;
+}
+export interface ServerResponse extends http.ServerResponse {
+ socket: Socket;
+ push?: (pathname: string, options?: PushOptions) => stream.Writable;
+}
+export declare type Socket = Partial & net.Socket;
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
+export declare type ServerOptions = spdy.ServerOptions & {
+ allowHalfOpen?: boolean | undefined;
+ pauseOnConnect?: boolean | undefined;
+} & http.ServerOptions &
+ tls.TlsOptions &
+ https.ServerOptions;
+export declare const notfoundrequestlistener: (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare const notfoundupgradelistener: (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
+export {};
diff --git a/lib/declaration.js b/lib/declaration.js
new file mode 100644
index 0000000..80bbf17
--- /dev/null
+++ b/lib/declaration.js
@@ -0,0 +1,9 @@
+export const notfoundrequestlistener = function (req, res) {
+ res.statusCode = 404;
+ res.write("404");
+ res.end();
+};
+export const notfoundupgradelistener = function (req, socket, head) {
+ socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
+ socket.destroy();
+};
diff --git a/lib/declaration.ts b/lib/declaration.ts
new file mode 100644
index 0000000..38f6978
--- /dev/null
+++ b/lib/declaration.ts
@@ -0,0 +1,48 @@
+import http from "http";
+import net from "net";
+import spdy from "spdy";
+import tls from "tls";
+import stream from "stream";
+import https from "https";
+export interface ServerRequest extends http.IncomingMessage {
+ socket: Socket;
+}
+interface PushOptions {
+ status?: number;
+ method?: string;
+ request?: http.OutgoingHttpHeaders;
+ response?: http.OutgoingHttpHeaders;
+}
+export interface ServerResponse extends http.ServerResponse {
+ socket: Socket;
+ push?: (pathname: string, options?: PushOptions) => stream.Writable;
+}
+export type Socket = Partial & net.Socket;
+export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
+export type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
+export type ServerOptions = spdy.ServerOptions & {
+ allowHalfOpen?: boolean | undefined;
+ pauseOnConnect?: boolean | undefined;
+} & http.ServerOptions &
+ tls.TlsOptions &
+ https.ServerOptions;
+export const notfoundrequestlistener = function (
+ req: ServerRequest,
+ res: ServerResponse
+) {
+ res.statusCode = 404;
+ res.write("404");
+ res.end();
+};
+export const notfoundupgradelistener = function (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) {
+ socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
+ socket.destroy();
+};
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 1e04550..3daa437 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,37 +1,13 @@
///
-import http from "http";
-import https from "https";
import net from "net";
-import spdy from "spdy";
-import tls from "tls";
-import stream from "stream";
-export interface ServerRequest extends http.IncomingMessage {
- socket: Socket;
-}
-interface PushOptions {
- status?: number;
- method?: string;
- request?: http.OutgoingHttpHeaders;
- response?: http.OutgoingHttpHeaders;
-}
-export interface ServerResponse extends http.ServerResponse {
- socket: Socket;
- push?: (pathname: string, options: PushOptions) => stream.Writable;
-}
-export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (
- req: ServerRequest,
- res: ServerResponse
-) => void;
-export declare type UpgradeListener = (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
-export declare type ServerOptions = spdy.ServerOptions;
+import {
+ RequestListener,
+ ServerOptions,
+ UpgradeListener,
+} from "./declaration.js";
declare function createServer(
config: ServerOptions,
requestListener?: RequestListener,
upgradeListener?: UpgradeListener
-): https.Server;
+): net.Server;
export { createServer };
diff --git a/lib/index.js b/lib/index.js
index 63c2efe..c7eff5d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,14 +1,10 @@
import http from "http";
+import net from "net";
import spdy from "spdy";
-const notfoundrequestlistener = function (req, res) {
- res.statusCode = 404;
- res.write("404");
- res.end();
-};
-const notfoundupgradelistener = function (req, socket, head) {
- socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
- socket.destroy();
-};
+import {
+ notfoundrequestlistener,
+ notfoundupgradelistener,
+} from "./declaration.js";
function createServer(
config,
requestListener = notfoundrequestlistener,
@@ -17,37 +13,24 @@ function createServer(
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
+ const servernet = net.createServer(config);
const serverhttp = http.createServer(config);
const serverspdy = spdy.createServer(config);
- serverhttp.addListener("connect", (request, socket, head) => {
- serverspdy.emit("connect", request, socket, head);
- });
- serverhttp.addListener("clientError", (error, socket) => {
- serverspdy.emit("clientError", error, socket);
- });
- serverhttp.addListener("upgrade", (request, socket, head) => {
- serverspdy.emit("upgrade", request, socket, head);
- });
- serverhttp.removeAllListeners("request");
- serverspdy.removeAllListeners("request");
- serverspdy.addListener("request", requestListener);
- serverhttp.addListener("request", (req, res) => {
- serverspdy.emit("request", req, res);
- });
+ serverhttp.addListener("upgrade", upgradeListener);
serverspdy.addListener("upgrade", upgradeListener);
- const onconnection = serverspdy.listeners("connection");
- serverspdy.removeAllListeners("connection");
+ serverhttp.addListener("request", requestListener);
+ serverspdy.addListener("request", requestListener);
function handletls(socket) {
- onconnection.forEach((listeners) =>
- Reflect.apply(listeners, serverspdy, [socket])
- );
+ serverspdy.emit("connection", socket);
}
function handlehttp(socket) {
serverhttp.emit("connection", socket);
}
- serverspdy.addListener("connection", connectionListener);
+ servernet.addListener("connection", connectionListener);
function connectionListener(socket) {
- socket.on("error", function onError() {});
+ if (!socket.listeners("error").length) {
+ socket.on("error", function () {});
+ }
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
@@ -65,6 +48,6 @@ function createServer(
}
}
}
- return serverspdy;
+ return servernet;
}
export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index 235d44e..8d01899 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,88 +1,61 @@
import http from "http";
-import https from "https";
import net from "net";
import spdy from "spdy";
-import tls from "tls";
-import stream from "stream";
+import {
+ notfoundrequestlistener,
+ notfoundupgradelistener,
+ RequestListener,
+ ServerOptions,
+ UpgradeListener,
+} from "./declaration.js";
-export interface ServerRequest extends http.IncomingMessage {
- socket: Socket;
-}
-interface PushOptions {
- status?: number;
- method?: string;
- request?: http.OutgoingHttpHeaders;
- response?: http.OutgoingHttpHeaders;
-}
-export interface ServerResponse extends http.ServerResponse {
- socket: Socket;
- push?: (pathname: string, options?: PushOptions) => stream.Writable;
-}
-export type Socket = Partial & net.Socket;
-export type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
-export type UpgradeListener = (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
-export type ServerOptions = spdy.ServerOptions;
-const notfoundrequestlistener = function (
- req: ServerRequest,
- res: ServerResponse
-) {
- res.statusCode = 404;
- res.write("404");
- res.end();
-};
-const notfoundupgradelistener = function (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) {
- socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
- socket.destroy();
-};
function createServer(
config: ServerOptions,
requestListener: RequestListener = notfoundrequestlistener,
upgradeListener: UpgradeListener = notfoundupgradelistener
-): https.Server {
+): net.Server {
if (!(typeof config === "object")) {
throw new Error("options are required!");
}
+ const servernet = net.createServer(config);
const serverhttp = http.createServer(config);
//@ts-ignore
const serverspdy = spdy.createServer(config);
-
- serverhttp.addListener(
- "upgrade",
- (request: ServerRequest, socket: Socket, head: Buffer) => {
- serverspdy.emit("upgrade", request, socket, head);
- }
- );
- serverhttp.removeAllListeners("request");
- serverspdy.removeAllListeners("request");
+ serverhttp.addListener("upgrade", upgradeListener);
+ serverspdy.addListener("upgrade", upgradeListener);
+ serverhttp.addListener("request", requestListener);
serverspdy.addListener("request", requestListener);
- serverhttp.addListener("request", (req, res) => {
- serverspdy.emit("request", req, res);
- });
+ // serverhttp.addListener(
+ // "upgrade",
+ // (request: ServerRequest, socket: Socket, head: Buffer) => {
+ // serverspdy.emit("upgrade", request, socket, head);
+ // }
+ // );
+ // serverhttp.removeAllListeners("request");
+ // serverspdy.removeAllListeners("request");
+ // serverspdy.addListener("request", requestListener);
+ // serverhttp.addListener("request", (req, res) => {
+ // serverspdy.emit("request", req, res);
+ // });
- serverspdy.addListener("upgrade", upgradeListener);
- const onconnection = serverspdy.listeners("connection");
- serverspdy.removeAllListeners("connection");
+ // serverspdy.addListener("upgrade", upgradeListener);
+ // const onconnection = serverspdy.listeners("connection");
+ // serverspdy.removeAllListeners("connection");
function handletls(socket: net.Socket) {
- onconnection.forEach((listeners: Function) =>
- Reflect.apply(listeners, serverspdy, [socket])
- );
+ serverspdy.emit("connection", socket);
+ // onconnection.forEach((listeners: Function) =>
+ // Reflect.apply(listeners, serverspdy, [socket])
+ // );
}
function handlehttp(socket: net.Socket) {
serverhttp.emit("connection", socket);
}
- serverspdy.addListener("connection", connectionListener);
-
+ // serverspdy.addListener("connection", connectionListener);
+ servernet.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
- socket.allowHalfOpen = false;
+ /* 类型“Socket”上不存在属性“allowHalfOpen” */
+ // socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
if (!socket.listeners("error").length) {
socket.on("error", function () {});
@@ -122,6 +95,6 @@ function createServer(
/* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
- return serverspdy;
+ return servernet;
}
export { createServer };
diff --git a/test/websocket.js b/test/websocket.js
index ba80bbd..a9feec7 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -20,7 +20,7 @@ const server = createServer(
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
+ res.writeHead(200, { "Content-Type": "text/html" });
res.end("websocket");
},
From 409bc4d724772ad15012150d0e9b1a85cac8aaed Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 17:37:08 +0800
Subject: [PATCH 074/125] =?UTF-8?q?websocket=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/index.js | 15 +++++++++++++++
test/websocket.js | 18 +++++++++++++++---
2 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 test/index.js
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..0d6fe03
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,15 @@
+let url = new URL(location.href);
+if (url.protocol === "https:") {
+ url.protocol = "wss:";
+} else {
+ if (url.protocol === "http:") {
+ url.protocol = "ws:";
+ }
+}
+
+let socket = new WebSocket(url.href);
+
+socket.addEventListener("close", console.log);
+socket.addEventListener("open", console.log);
+socket.addEventListener("error", console.log);
+socket.addEventListener("message", console.log);
diff --git a/test/websocket.js b/test/websocket.js
index a9feec7..d2b942b 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -19,10 +19,22 @@ const server = createServer(
key: fs.readFileSync(path.join(__dirname, "server.key")),
cert: fs.readFileSync(path.join(__dirname, "server.crt")),
},
- function (req, res) {
- res.writeHead(200, { "Content-Type": "text/html" });
+ async function (req, res) {
+ if (req.url === "/") {
+ res.writeHead(200, { "Content-Type": "text/html" });
- res.end("websocket");
+ res.end("websocket");
+ } else if (req.url === "/index.js") {
+ res.writeHead(200, { "Content-Type": "text/javascript" });
+ const jsfile = await fs.promises.readFile(
+ path.join(__dirname, "index.js")
+ );
+ res.write(jsfile);
+ res.end();
+ } else {
+ res.statusCode = 404;
+ res.end();
+ }
},
function (req, socket, head) {
wsServer.handleUpgrade(req, socket, head, function done(ws) {
From ee3edd95dee6266f781e908f21c18d29d7c14960 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 17:42:03 +0800
Subject: [PATCH 075/125] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
lib/declaration.d.ts | 4 ++--
lib/declaration.js | 4 ++--
lib/declaration.ts | 4 ++--
lib/index.d.ts | 3 ++-
lib/index.js | 12 +++++-------
lib/index.ts | 12 ++++++------
test/websocket.js | 4 +++-
8 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index 1e37e73..ecbb2a7 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,7 @@ declare function createServer(
config: ServerOptions,
requestListener?: RequestListener,
upgradeListener?: UpgradeListener
-): https.Server;
+): net.Server;
```
The `requestListener` is a function which is automatically added to the 'request' event
diff --git a/lib/declaration.d.ts b/lib/declaration.d.ts
index c59f793..490a601 100644
--- a/lib/declaration.d.ts
+++ b/lib/declaration.d.ts
@@ -34,11 +34,11 @@ export declare type ServerOptions = spdy.ServerOptions & {
} & http.ServerOptions &
tls.TlsOptions &
https.ServerOptions;
-export declare const notfoundrequestlistener: (
+export declare const requestNotFound: (
req: ServerRequest,
res: ServerResponse
) => void;
-export declare const notfoundupgradelistener: (
+export declare const upgradeNotFound: (
req: ServerRequest,
socket: Socket,
head: Buffer
diff --git a/lib/declaration.js b/lib/declaration.js
index 80bbf17..ff49eb9 100644
--- a/lib/declaration.js
+++ b/lib/declaration.js
@@ -1,9 +1,9 @@
-export const notfoundrequestlistener = function (req, res) {
+export const requestNotFound = function (req, res) {
res.statusCode = 404;
res.write("404");
res.end();
};
-export const notfoundupgradelistener = function (req, socket, head) {
+export const upgradeNotFound = function (req, socket, head) {
socket.write(`HTTP/1.1 404 Not Found\r\nConnection: keep-alive\r\n\r\n`);
socket.destroy();
};
diff --git a/lib/declaration.ts b/lib/declaration.ts
index 38f6978..a3c0863 100644
--- a/lib/declaration.ts
+++ b/lib/declaration.ts
@@ -30,7 +30,7 @@ export type ServerOptions = spdy.ServerOptions & {
} & http.ServerOptions &
tls.TlsOptions &
https.ServerOptions;
-export const notfoundrequestlistener = function (
+export const requestNotFound = function (
req: ServerRequest,
res: ServerResponse
) {
@@ -38,7 +38,7 @@ export const notfoundrequestlistener = function (
res.write("404");
res.end();
};
-export const notfoundupgradelistener = function (
+export const upgradeNotFound = function (
req: ServerRequest,
socket: Socket,
head: Buffer
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 3daa437..106f240 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -5,9 +5,10 @@ import {
ServerOptions,
UpgradeListener,
} from "./declaration.js";
+export * from "./declaration.js";
+export { createServer };
declare function createServer(
config: ServerOptions,
requestListener?: RequestListener,
upgradeListener?: UpgradeListener
): net.Server;
-export { createServer };
diff --git a/lib/index.js b/lib/index.js
index c7eff5d..bd4a342 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,14 +1,13 @@
import http from "http";
import net from "net";
import spdy from "spdy";
-import {
- notfoundrequestlistener,
- notfoundupgradelistener,
-} from "./declaration.js";
+import { requestNotFound, upgradeNotFound } from "./declaration.js";
+export * from "./declaration.js";
+export { createServer };
function createServer(
config,
- requestListener = notfoundrequestlistener,
- upgradeListener = notfoundupgradelistener
+ requestListener = requestNotFound,
+ upgradeListener = upgradeNotFound
) {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -50,4 +49,3 @@ function createServer(
}
return servernet;
}
-export { createServer };
diff --git a/lib/index.ts b/lib/index.ts
index 8d01899..14323d0 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -2,17 +2,18 @@ import http from "http";
import net from "net";
import spdy from "spdy";
import {
- notfoundrequestlistener,
- notfoundupgradelistener,
+ requestNotFound,
+ upgradeNotFound,
RequestListener,
ServerOptions,
UpgradeListener,
} from "./declaration.js";
-
+export * from "./declaration.js";
+export { createServer };
function createServer(
config: ServerOptions,
- requestListener: RequestListener = notfoundrequestlistener,
- upgradeListener: UpgradeListener = notfoundupgradelistener
+ requestListener: RequestListener = requestNotFound,
+ upgradeListener: UpgradeListener = upgradeNotFound
): net.Server {
if (!(typeof config === "object")) {
throw new Error("options are required!");
@@ -97,4 +98,3 @@ function createServer(
return servernet;
}
-export { createServer };
diff --git a/test/websocket.js b/test/websocket.js
index d2b942b..515d465 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -23,7 +23,9 @@ const server = createServer(
if (req.url === "/") {
res.writeHead(200, { "Content-Type": "text/html" });
- res.end("websocket");
+ res.end(
+ "websocket"
+ );
} else if (req.url === "/index.js") {
res.writeHead(200, { "Content-Type": "text/javascript" });
const jsfile = await fs.promises.readFile(
From d7c70e9995b9d31738722652a374a1a1f7c49cb8 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 17:43:32 +0800
Subject: [PATCH 076/125] Update index.js
---
test/index.js | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/test/index.js b/test/index.js
index 0d6fe03..f2f1b57 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,10 +1,8 @@
let url = new URL(location.href);
if (url.protocol === "https:") {
url.protocol = "wss:";
-} else {
- if (url.protocol === "http:") {
- url.protocol = "ws:";
- }
+} else if (url.protocol === "http:") {
+ url.protocol = "ws:";
}
let socket = new WebSocket(url.href);
From 3938fd29c9039c1b2b40a87ab486359bbe747cc7 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 18:02:22 +0800
Subject: [PATCH 077/125] Update index.ts
---
lib/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/index.ts b/lib/index.ts
index 14323d0..6a5cdc9 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -15,7 +15,7 @@ function createServer(
requestListener: RequestListener = requestNotFound,
upgradeListener: UpgradeListener = upgradeNotFound
): net.Server {
- if (!(typeof config === "object")) {
+ if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
From 947bbc28d29cdf859bcd0e4dfb02bfd3f7a9060d Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 18:02:55 +0800
Subject: [PATCH 078/125] Update index.js
---
lib/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/index.js b/lib/index.js
index bd4a342..93fc140 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,7 +9,7 @@ function createServer(
requestListener = requestNotFound,
upgradeListener = upgradeNotFound
) {
- if (!(typeof config === "object")) {
+ if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
const servernet = net.createServer(config);
From 5240718d1d070dd37124d85915b544881d6483f8 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 18:06:05 +0800
Subject: [PATCH 079/125] Update README.md
---
README.md | 78 ++++++++++++++++++++++++++++---------------------------
1 file changed, 40 insertions(+), 38 deletions(-)
diff --git a/README.md b/README.md
index ecbb2a7..5633eee 100644
--- a/README.md
+++ b/README.md
@@ -42,22 +42,21 @@ https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/webso
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
const fs = require("fs");
const port = 9000;
-httpolyglot
- .createServer(
- {
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
- },
- function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end(
- ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
- );
- }
- )
- .listen(port, "localhost", function () {
- console.log("httpolyglot server listening on port " + port);
- });
+const server = httpolyglot.createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end(
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
+ );
+ }
+);
+server.listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
```
- redirect all http connections to https:
@@ -66,31 +65,34 @@ httpolyglot
const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
const fs = require("fs");
const port = 9000;
-httpolyglot
- .createServer(
- {
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
- },
- function (req, res) {
- if (!("encrypted" in req.socket)) {
- const host = req.headers["host"];
- const originurl = req.url || "";
- const tourl = new URL(originurl, "https://" + host);
- tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href });
- return res.end();
- } else {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end("Welcome, HTTPS user!");
- }
+const server = httpolyglot.createServer(
+ {
+ key: fs.readFileSync("server.key"),
+ cert: fs.readFileSync("server.crt"),
+ },
+ function (req, res) {
+ if (!("encrypted" in req.socket)) {
+ const host = req.headers["host"];
+ const originurl = req.url || "";
+ const tourl = new URL(originurl, "https://" + host);
+ tourl.port = String(port);
+ res.writeHead(302, { Location: tourl.href });
+ return res.end();
+ } else {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Welcome, HTTPS user!");
}
- )
- .listen(port, "localhost", function () {
- console.log("httpolyglot server listening on port " + port);
- });
+ }
+);
+server.listen(port, "localhost", function () {
+ console.log("httpolyglot server listening on port " + port);
+});
```
+- create a "404 not found" server
+
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/notfound.js
+
# API
## Exports
From db73d2d7cf43c316420f7973578d3f1e7a897868 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 18:08:23 +0800
Subject: [PATCH 080/125] Update README.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5633eee..6907ba1 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ const ishttp2 = "h2" === req.socket.alpnProtocol;
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/push.js
-- Websocket
+- Websocket server
https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/websocket.js
@@ -113,6 +113,8 @@ The `requestListener` is a function which is automatically added to the 'request
The `upgradeListener` is a function which is automatically added to the 'upgrade' event
+If no "requestListener" or "upgradeListener" is provided, the default "404 not found" listener will be used instead.
+
# How it Works
https://github.com/lvgithub/blog/blob/master/http_and_https_over_same_port/README.MD
From 2d3f0a85d4f7652d8fe6c0532bac0d3e979f798f Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 18:10:17 +0800
Subject: [PATCH 081/125] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6907ba1..454ddaf 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Determine if the connection is over tls.
const istls = "encrypted" in req.socket;
```
-Determine if the connection is http/2.
+Determine if the connection is `http/2`.
```js
const ishttp2 = "h2" === req.socket.alpnProtocol;
From 7735a8a70fdc084c49686cd41fbd81f15726a0ec Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:16:01 +0800
Subject: [PATCH 082/125] =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90ssl?=
=?UTF-8?q?=E8=AF=81=E4=B9=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 8 +-
package.json | 9 +-
server.crt.pem | 22 ++++
server.key.pem | 28 +++++
test/fetch.js | 21 ++++
test/generate-ssl-cert.ps1 | 1 +
test/notfound.js | 5 +-
test/open.js | 5 +
test/push.js | 5 +-
test/redirect.js | 5 +-
test/{server.crt => server.crt.pem} | 0
test/{server.key => server.key.pem} | 0
test/simple.js | 5 +-
test/test.js | 1 +
test/urls.js | 8 ++
test/websocket.js | 5 +-
yarn.lock | 166 ++++++++++++++++++++++++++--
17 files changed, 269 insertions(+), 25 deletions(-)
create mode 100644 server.crt.pem
create mode 100644 server.key.pem
create mode 100644 test/fetch.js
create mode 100644 test/generate-ssl-cert.ps1
create mode 100644 test/open.js
rename test/{server.crt => server.crt.pem} (100%)
rename test/{server.key => server.key.pem} (100%)
create mode 100644 test/urls.js
diff --git a/README.md b/README.md
index 454ddaf..c9e362f 100644
--- a/README.md
+++ b/README.md
@@ -44,8 +44,8 @@ const fs = require("fs");
const port = 9000;
const server = httpolyglot.createServer(
{
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
+ key: fs.readFileSync("server.key.pem"),
+ cert: fs.readFileSync("server.crt.pem"),
},
function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" });
@@ -67,8 +67,8 @@ const fs = require("fs");
const port = 9000;
const server = httpolyglot.createServer(
{
- key: fs.readFileSync("server.key"),
- cert: fs.readFileSync("server.crt"),
+ key: fs.readFileSync("server.key.pem"),
+ cert: fs.readFileSync("server.crt.pem"),
},
function (req, res) {
if (!("encrypted" in req.socket)) {
diff --git a/package.json b/package.json
index e39a2f2..91c9066 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,8 @@
"version": "1.0.0",
"main": "./lib/index.js",
"scripts": {
+ "fetch": "node --experimental-modules test/fetch.js",
+ "open": "node --experimental-modules test/open.js",
"debug": "node --inspect test/test.js",
"build": "tsc",
"test": "node --experimental-modules test/test.js",
@@ -27,12 +29,15 @@
"@types/spdy": "^3.4.4"
},
"devDependencies": {
+ "fetch-h2": "^2.4.5",
+ "node-fetch": "^3.0.0-beta.4",
"@types/ws": "^7.2.4",
- "ws": "^7.2.3",
+ "open": "^7.0.3",
"prettier": "^2.0.4",
"spdy": "^4.0.2",
"tslib": "^1.11.1",
- "typescript": "^3.8.3"
+ "typescript": "^3.8.3",
+ "ws": "^7.2.3"
},
"license": "ISC",
"repository": {
diff --git a/server.crt.pem b/server.crt.pem
new file mode 100644
index 0000000..38f35a8
--- /dev/null
+++ b/server.crt.pem
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDrTCCApWgAwIBAgIUOrrtwPlFPMGGK0ZaGSAKwc7dPwMwDQYJKoZIhvcNAQEL
+BQAwZjELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
+aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxDzANBgNV
+BAMMBmJveXVzYzAeFw0yMDA0MjAxMTEzNDBaFw0yMTA0MjAxMTEzNDBaMGYxCzAJ
+BgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdoYWkx
+DzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMQ8wDQYDVQQDDAZib3l1
+c2MwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEZCIvX4y+wAYIrjAn
+XJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLkCldO
+7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlbp0BT
+NfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gwMUc5
+bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIuiwMf
+y3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfHBJg/
+EQODAgMBAAGjUzBRMB0GA1UdDgQWBBRIZWGS0XoX9JORb2dUGVybYd312DAfBgNV
+HSMEGDAWgBRIZWGS0XoX9JORb2dUGVybYd312DAPBgNVHRMBAf8EBTADAQH/MA0G
+CSqGSIb3DQEBCwUAA4IBAQB09d3fy74u0GYd9AUnGAOjqxG64bQiF3/Z1OOTT3RS
+cQIFTpSDQyw9DfcUXpIqhdD3bnjPkqDlmirPAt1fqJvY1/k3758U1iAvPcqvhyjj
+vDKP+FKHAYFA44YhrUIAadi/g6uuwFVSovzBOE7oefxL5QnBXHSSPBUskdd5GORZ
+PqctPP8ZGtmZkyXRJI8t/rnnhjfnn9XyQkGy5gFdktGoedR7Wf2UDtKxWLv8d4QQ
+SLi2NIJT4nO6oRspQQyBpmBwjbARmMCyfjpO7MQqNsdw7W3LAHb5M3UepidokfoP
+iOYU2Ag2K6QHTsb+PTM8bwVsj2RnvogQn0y3Wvlvxtrp
+-----END CERTIFICATE-----
diff --git a/server.key.pem b/server.key.pem
new file mode 100644
index 0000000..1b0799c
--- /dev/null
+++ b/server.key.pem
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEZCIvX4y+wAYI
+rjAnXJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLk
+CldO7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlb
+p0BTNfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gw
+MUc5bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIu
+iwMfy3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfH
+BJg/EQODAgMBAAECggEAOLDHBXHJiQ6ZL0xI7jPYmWzHlc4U27wox+vI7x0r+jOo
+BcOZDHuPjge6JYYYnCmixJA8+dhh+TaMyRMLHOdn0LVeb3SxMLzLX9G93d3R/0nM
+AYrJVwxhSZsIC9a7PoT3+GEpnFpkgjEARKrE8MAznNPDDNpAKOQ/WAnYstBUITzN
+7jsct2GQZ1j2acDlH7zsOGiM3nPf1cvg7IVomO3ZlfC0cyo370zDiAZwt88TpzE7
+vLrsVvuIUKbAlmbSzYWx5P5HBeQDFfSbE5iUvkARwZTgMqV9yXqefAitImsSQd4M
+PYATStqYzagj+PgB3PV28IcAS5AGI4G09ieljmJHoQKBgQDn9Usgv/VP33m6RofH
+FHclVcp4J5YNoCQSE3hjIwOg+q0HZieDJSbFxSel+iZSogyw9xxTE3vvG2C3BFwM
+TVAHgodBPAKDcoXgoyTcXTLXfVe6yqfz1zLvXX29qOLbvLlfa9KvDVh9ipGedXxw
+oRMM6nFeRPNQNj/i76dzLxjbuwKBgQDYvx2PXWQqI7mM/aZ07h66t+L5dxyO6lFK
+fOBxkw9IbYE9vY9qVooup1n3WOB6sPbwJfJtFriKh2Uu5rcp+icV1THp0JGnW6mK
+y8oRV1R0+Iq13/IkDKoFgFur3Y3ts219p2rOTI6BDEgkBRaqtJtvOrrky8LYoZxG
+OTFOApMm2QKBgQDQJww7IGeIPLfk1EQl/5SH2Xvu5T8/jPSxj+1ZsWMhQ7KgUCin
+BGDN2wWgaWGYh7kx2R7+4h42TPA2bGAZ3gsyIg00GiD7SnsfQefjJHNqcx2WDyQ2
+qmgX62LaHsMtgycqnPycgDJnvkC83RtFixYoYf5IJUHfOj+Ma5ltwNbi3wKBgBkl
+GtXN/NfSqy0LJCt+kHwS5zcPtXVzA5lDoXormGNLqOmzuxaYEZHWAl7qpag2LX+w
+t04mi6QujvOA+pDZH32t7Qt2Ed+7h5C9kaSvX/Ht/5GX+GxsN7FJsdjfbB6+aR5h
+tMdYJFQeS6Q6HuYQ69Ncmd//L4yYOxv+eJTXQaEJAoGAARX5kUJhSz67fshH6xa6
+oayPo+/RRfehuWiplidBSNG2HYSRkw48/e7BtZ4NQeGMZii3+c6s1Mb9eytdxPdi
+bn+NmO/IogBH3jIZ/gV6u5RXQ+X7YaJ76GaOy7oT+fGmr3Dnbs4wJvs+y5Zq4v/K
+OTUaXDYBXqyjX+afyva87DI=
+-----END PRIVATE KEY-----
diff --git a/test/fetch.js b/test/fetch.js
new file mode 100644
index 0000000..c7a248c
--- /dev/null
+++ b/test/fetch.js
@@ -0,0 +1,21 @@
+import { urls } from "./urls.js";
+
+process.on("unhandledRejection", console.error);
+
+import fetch1 from "node-fetch";
+
+import fetch2 from "fetch-h2";
+
+// @ts-ignore
+const fetcharr = [fetch1.default, fetch2.fetch];
+Promise.all(
+ urls
+ .map((url) =>
+ fetcharr.map((fetch) => {
+ return fetch(url, { redirect: "manual" }).then((r) =>
+ Promise.all([r, r.text()])
+ );
+ })
+ )
+ .flat(1 / 0)
+).then(console.log);
diff --git a/test/generate-ssl-cert.ps1 b/test/generate-ssl-cert.ps1
new file mode 100644
index 0000000..5932dae
--- /dev/null
+++ b/test/generate-ssl-cert.ps1
@@ -0,0 +1 @@
+openssl req -x509 -days 365 -newkey rsa:2048 -nodes -sha256 -subj "/C=CN/ST=Shanghai/L=Shanghai/O=boyusc/OU=boyusc/CN=boyusc" -keyout "server.key.pem" -out "server.crt.pem"
\ No newline at end of file
diff --git a/test/notfound.js b/test/notfound.js
index cd99806..1b8b0f1 100644
--- a/test/notfound.js
+++ b/test/notfound.js
@@ -5,11 +5,12 @@ import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
+// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer({
- key: fs.readFileSync(path.join(__dirname, "server.key")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
});
server.listen(port, "localhost", function () {
diff --git a/test/open.js b/test/open.js
new file mode 100644
index 0000000..250dd30
--- /dev/null
+++ b/test/open.js
@@ -0,0 +1,5 @@
+import open from "open";
+import { urls } from "./urls.js";
+
+Promise.all(urls.map((url) => open(url))).then((p) => console.log(p));
+process.on("unhandledRejection", console.error);
diff --git a/test/push.js b/test/push.js
index 620d690..559492f 100644
--- a/test/push.js
+++ b/test/push.js
@@ -5,12 +5,13 @@ import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
+// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
},
(req, res) => {
if (req.url == "/main.js") {
diff --git a/test/redirect.js b/test/redirect.js
index 9703a40..8a0c8e7 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -4,13 +4,14 @@ import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
+// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const port = 9001;
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
},
function (req, res) {
if ("encrypted" in req.socket) {
diff --git a/test/server.crt b/test/server.crt.pem
similarity index 100%
rename from test/server.crt
rename to test/server.crt.pem
diff --git a/test/server.key b/test/server.key.pem
similarity index 100%
rename from test/server.key
rename to test/server.key.pem
diff --git a/test/simple.js b/test/simple.js
index def08d4..1bbf630 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -5,12 +5,13 @@ import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
+// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
},
async function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
diff --git a/test/test.js b/test/test.js
index 3b08abe..4b419e1 100755
--- a/test/test.js
+++ b/test/test.js
@@ -3,3 +3,4 @@ import "./simple.js";
import "./push.js";
import "./redirect.js";
import "./websocket.js";
+process.on("unhandledRejection", console.error);
diff --git a/test/urls.js b/test/urls.js
new file mode 100644
index 0000000..ca0b22d
--- /dev/null
+++ b/test/urls.js
@@ -0,0 +1,8 @@
+const ports = [8998, 9002, 9001, 9000, 8999];
+const host = "localhost";
+const protocols = ["https:", "http:"];
+const urls = protocols
+ .map((protocol) => ports.map((port) => `${protocol}//${host}:${port}/`))
+ // @ts-ignore
+ .flat(1 / 0);
+export { urls };
diff --git a/test/websocket.js b/test/websocket.js
index 515d465..5edde4c 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -12,12 +12,13 @@ wsServer.on("connection", (websocket, req) => {
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
});
+// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt")),
+ key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
+ cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
},
async function (req, res) {
if (req.url === "/") {
diff --git a/yarn.lock b/yarn.lock
index 55547ed..842c6db 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -14,6 +14,11 @@
dependencies:
"@types/node" "*"
+"@types/tough-cookie@^2.3.6":
+ version "2.3.7"
+ resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-2.3.7.tgz#979434b5900f9d710f5d4e15c466cadb8e9fdc47"
+ integrity sha512-rMQbgMGxnLsdn8e9aPVyuN+zMQLrZ2QW8xlv7eWS1mydfGXN+tsTKffcIzd8rGCcLdmi3xvQw2MDaZI1bBNTaw==
+
"@types/ws@^7.2.4":
version "7.2.4"
resolved "https://registry.npmjs.org/@types/ws/-/ws-7.2.4.tgz#b3859f7b9c243b220efac9716ec42c716a72969d"
@@ -21,11 +26,35 @@
dependencies:
"@types/node" "*"
+already@^1.12.0:
+ version "1.12.0"
+ resolved "https://registry.yarnpkg.com/already/-/already-1.12.0.tgz#50f63ed461a62be5dd37d05795766bf0e685f3c6"
+ integrity sha512-JOq+vzTKA3qheL4rOcTYvdUwUhLFrUSiRshlDxxj+7CJTQlw9qHGveuMzEbyGRfoOscREA1gqJxxTnK7GDAfxQ==
+ dependencies:
+ throat "^5.0.0"
+
+buffer-from@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
+ integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
+
+callguard@^1.2.1:
+ version "1.2.1"
+ resolved "https://registry.yarnpkg.com/callguard/-/callguard-1.2.1.tgz#3d8df2ea91c946abf1c43b7d6abde23d3aecfdbb"
+ integrity sha512-QTxtuE+QrPA/ZStfYEf/IL1RqyOEpg3CMKp35oTs4n91WveYjbnbPJ0O2ob+RxhPzOuvb0KgQvYwJzhZ6nswXQ==
+
core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
+data-uri-to-buffer@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.0.tgz#8a3088a5efd3f53c3682343313c6895d498eb8d7"
+ integrity sha512-MJ6mFTZ+nPQO+39ua/ltwNePXrfdF3Ww0wP1Od7EePySXN1cP9XNqRQOG3FxTfipp8jx898LUCgBCEP11Qw/ZQ==
+ dependencies:
+ buffer-from "^1.1.1"
+
debug@^4.1.0:
version "4.1.1"
resolved "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
@@ -38,6 +67,38 @@ detect-node@^2.0.4:
resolved "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz#014ee8f8f669c5c58023da64b8179c083a28c46c"
integrity sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==
+end-of-stream@^1.1.0:
+ version "1.4.4"
+ resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
+ integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
+ dependencies:
+ once "^1.4.0"
+
+fetch-blob@^1.0.5:
+ version "1.0.5"
+ resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-1.0.5.tgz#5cc86a8740236c38d8073b153c8b51be5f3dc11e"
+ integrity sha512-BIggzO037jmCrZmtgntzCD2ymEaWgw9OMJsfX7FOS1jXGqKW9FEhETJN8QK4KxzIJknRl3RQdyzz34of+NNTMQ==
+
+fetch-h2@^2.4.5:
+ version "2.4.5"
+ resolved "https://registry.yarnpkg.com/fetch-h2/-/fetch-h2-2.4.5.tgz#aeccd1d47e0d0942b0477f857d27c45d4cbb661c"
+ integrity sha512-Nl6wvKqwHPBKlGbXQsnA55EgzI62p/pTb5ISrfxJEAb7ShwcrITEQHAVHKiuf9Z3ulMd64fkildG/bQB4J3qzw==
+ dependencies:
+ "@types/tough-cookie" "^2.3.6"
+ already "^1.12.0"
+ callguard "^1.2.1"
+ get-stream "^5.1.0"
+ through2 "^3.0.1"
+ to-arraybuffer "^1.0.1"
+ tough-cookie "^3.0.1"
+
+get-stream@^5.1.0:
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9"
+ integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==
+ dependencies:
+ pump "^3.0.0"
+
handle-thing@^2.0.0:
version "2.0.1"
resolved "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
@@ -63,6 +124,21 @@ inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3:
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
+ip-regex@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
+ integrity sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=
+
+is-docker@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.0.0.tgz#2cb0df0e75e2d064fe1864c37cdeacb7b2dcf25b"
+ integrity sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ==
+
+is-wsl@^2.1.1:
+ version "2.1.1"
+ resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.1.1.tgz#4a1c152d429df3d441669498e2486d3596ebaf1d"
+ integrity sha512-umZHcSrwlDHo2TGMXv0DZ8dIUGunZ2Iv68YZnrmCiBPkZ4aaOhtv7pXJKeki9k3qJ3RJr0cDyitcl5wEH3AYog==
+
isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -78,11 +154,34 @@ ms@^2.1.1:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
+node-fetch@^3.0.0-beta.4:
+ version "3.0.0-beta.4"
+ resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.0.0-beta.4.tgz#f5fcc70e506314c90df4f5f19e81cff55aa1ecea"
+ integrity sha512-NxI746RCCuW5XmvGEOVPMFksmoMFEaWUEhNAGY5VLJ9qmit1mCEfRTHdomZuMe94FuY2QO2DLrWYe70HT7ubqw==
+ dependencies:
+ data-uri-to-buffer "^3.0.0"
+ fetch-blob "^1.0.5"
+
obuf@^1.0.0, obuf@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
integrity sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==
+once@^1.3.1, once@^1.4.0:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
+ integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
+ dependencies:
+ wrappy "1"
+
+open@^7.0.3:
+ version "7.0.3"
+ resolved "https://registry.yarnpkg.com/open/-/open-7.0.3.tgz#db551a1af9c7ab4c7af664139930826138531c48"
+ integrity sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA==
+ dependencies:
+ is-docker "^2.0.0"
+ is-wsl "^2.1.1"
+
prettier@^2.0.4:
version "2.0.4"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.0.4.tgz#2d1bae173e355996ee355ec9830a7a1ee05457ef"
@@ -93,6 +192,33 @@ process-nextick-args@~2.0.0:
resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
+psl@^1.1.28:
+ version "1.8.0"
+ resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"
+ integrity sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==
+
+pump@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
+ integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==
+ dependencies:
+ end-of-stream "^1.1.0"
+ once "^1.3.1"
+
+punycode@^2.1.1:
+ version "2.1.1"
+ resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
+ integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
+
+"readable-stream@2 || 3", readable-stream@^3.0.6:
+ version "3.6.0"
+ resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
+ integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
+ dependencies:
+ inherits "^2.0.3"
+ string_decoder "^1.1.1"
+ util-deprecate "^1.0.1"
+
readable-stream@^2.0.1:
version "2.3.7"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
@@ -106,15 +232,6 @@ readable-stream@^2.0.1:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
-readable-stream@^3.0.6:
- version "3.6.0"
- resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
- integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
- dependencies:
- inherits "^2.0.3"
- string_decoder "^1.1.1"
- util-deprecate "^1.0.1"
-
safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@@ -167,6 +284,32 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"
+throat@^5.0.0:
+ version "5.0.0"
+ resolved "https://registry.yarnpkg.com/throat/-/throat-5.0.0.tgz#c5199235803aad18754a667d659b5e72ce16764b"
+ integrity sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==
+
+through2@^3.0.1:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a"
+ integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==
+ dependencies:
+ readable-stream "2 || 3"
+
+to-arraybuffer@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43"
+ integrity sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=
+
+tough-cookie@^3.0.1:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-3.0.1.tgz#9df4f57e739c26930a018184887f4adb7dca73b2"
+ integrity sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==
+ dependencies:
+ ip-regex "^2.1.0"
+ psl "^1.1.28"
+ punycode "^2.1.1"
+
tslib@^1.11.1:
version "1.11.1"
resolved "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
@@ -189,6 +332,11 @@ wbuf@^1.1.0, wbuf@^1.7.3:
dependencies:
minimalistic-assert "^1.0.0"
+wrappy@1:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
+ integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
+
ws@^7.2.3:
version "7.2.3"
resolved "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46"
From 87253dcebd001d4b4570fa9b8db06897b75e5ad7 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:19:56 +0800
Subject: [PATCH 083/125] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E8=AF=81=E4=B9=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server.crt.pem | 22 -------------------
server.key.pem | 28 ------------------------
test/server.crt.pem | 40 +++++++++++++++++-----------------
test/server.key.pem | 52 ++++++++++++++++++++++-----------------------
4 files changed, 46 insertions(+), 96 deletions(-)
delete mode 100644 server.crt.pem
delete mode 100644 server.key.pem
diff --git a/server.crt.pem b/server.crt.pem
deleted file mode 100644
index 38f35a8..0000000
--- a/server.crt.pem
+++ /dev/null
@@ -1,22 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDrTCCApWgAwIBAgIUOrrtwPlFPMGGK0ZaGSAKwc7dPwMwDQYJKoZIhvcNAQEL
-BQAwZjELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
-aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxDzANBgNV
-BAMMBmJveXVzYzAeFw0yMDA0MjAxMTEzNDBaFw0yMTA0MjAxMTEzNDBaMGYxCzAJ
-BgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdoYWkx
-DzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMQ8wDQYDVQQDDAZib3l1
-c2MwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEZCIvX4y+wAYIrjAn
-XJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLkCldO
-7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlbp0BT
-NfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gwMUc5
-bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIuiwMf
-y3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfHBJg/
-EQODAgMBAAGjUzBRMB0GA1UdDgQWBBRIZWGS0XoX9JORb2dUGVybYd312DAfBgNV
-HSMEGDAWgBRIZWGS0XoX9JORb2dUGVybYd312DAPBgNVHRMBAf8EBTADAQH/MA0G
-CSqGSIb3DQEBCwUAA4IBAQB09d3fy74u0GYd9AUnGAOjqxG64bQiF3/Z1OOTT3RS
-cQIFTpSDQyw9DfcUXpIqhdD3bnjPkqDlmirPAt1fqJvY1/k3758U1iAvPcqvhyjj
-vDKP+FKHAYFA44YhrUIAadi/g6uuwFVSovzBOE7oefxL5QnBXHSSPBUskdd5GORZ
-PqctPP8ZGtmZkyXRJI8t/rnnhjfnn9XyQkGy5gFdktGoedR7Wf2UDtKxWLv8d4QQ
-SLi2NIJT4nO6oRspQQyBpmBwjbARmMCyfjpO7MQqNsdw7W3LAHb5M3UepidokfoP
-iOYU2Ag2K6QHTsb+PTM8bwVsj2RnvogQn0y3Wvlvxtrp
------END CERTIFICATE-----
diff --git a/server.key.pem b/server.key.pem
deleted file mode 100644
index 1b0799c..0000000
--- a/server.key.pem
+++ /dev/null
@@ -1,28 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEZCIvX4y+wAYI
-rjAnXJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLk
-CldO7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlb
-p0BTNfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gw
-MUc5bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIu
-iwMfy3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfH
-BJg/EQODAgMBAAECggEAOLDHBXHJiQ6ZL0xI7jPYmWzHlc4U27wox+vI7x0r+jOo
-BcOZDHuPjge6JYYYnCmixJA8+dhh+TaMyRMLHOdn0LVeb3SxMLzLX9G93d3R/0nM
-AYrJVwxhSZsIC9a7PoT3+GEpnFpkgjEARKrE8MAznNPDDNpAKOQ/WAnYstBUITzN
-7jsct2GQZ1j2acDlH7zsOGiM3nPf1cvg7IVomO3ZlfC0cyo370zDiAZwt88TpzE7
-vLrsVvuIUKbAlmbSzYWx5P5HBeQDFfSbE5iUvkARwZTgMqV9yXqefAitImsSQd4M
-PYATStqYzagj+PgB3PV28IcAS5AGI4G09ieljmJHoQKBgQDn9Usgv/VP33m6RofH
-FHclVcp4J5YNoCQSE3hjIwOg+q0HZieDJSbFxSel+iZSogyw9xxTE3vvG2C3BFwM
-TVAHgodBPAKDcoXgoyTcXTLXfVe6yqfz1zLvXX29qOLbvLlfa9KvDVh9ipGedXxw
-oRMM6nFeRPNQNj/i76dzLxjbuwKBgQDYvx2PXWQqI7mM/aZ07h66t+L5dxyO6lFK
-fOBxkw9IbYE9vY9qVooup1n3WOB6sPbwJfJtFriKh2Uu5rcp+icV1THp0JGnW6mK
-y8oRV1R0+Iq13/IkDKoFgFur3Y3ts219p2rOTI6BDEgkBRaqtJtvOrrky8LYoZxG
-OTFOApMm2QKBgQDQJww7IGeIPLfk1EQl/5SH2Xvu5T8/jPSxj+1ZsWMhQ7KgUCin
-BGDN2wWgaWGYh7kx2R7+4h42TPA2bGAZ3gsyIg00GiD7SnsfQefjJHNqcx2WDyQ2
-qmgX62LaHsMtgycqnPycgDJnvkC83RtFixYoYf5IJUHfOj+Ma5ltwNbi3wKBgBkl
-GtXN/NfSqy0LJCt+kHwS5zcPtXVzA5lDoXormGNLqOmzuxaYEZHWAl7qpag2LX+w
-t04mi6QujvOA+pDZH32t7Qt2Ed+7h5C9kaSvX/Ht/5GX+GxsN7FJsdjfbB6+aR5h
-tMdYJFQeS6Q6HuYQ69Ncmd//L4yYOxv+eJTXQaEJAoGAARX5kUJhSz67fshH6xa6
-oayPo+/RRfehuWiplidBSNG2HYSRkw48/e7BtZ4NQeGMZii3+c6s1Mb9eytdxPdi
-bn+NmO/IogBH3jIZ/gV6u5RXQ+X7YaJ76GaOy7oT+fGmr3Dnbs4wJvs+y5Zq4v/K
-OTUaXDYBXqyjX+afyva87DI=
------END PRIVATE KEY-----
diff --git a/test/server.crt.pem b/test/server.crt.pem
index 0c6b514..38f35a8 100644
--- a/test/server.crt.pem
+++ b/test/server.crt.pem
@@ -1,22 +1,22 @@
-----BEGIN CERTIFICATE-----
-MIIDjzCCAnegAwIBAgIJANiEfJkuqhEaMA0GCSqGSIb3DQEBCwUAMF4xCzAJBgNV
-BAYTAlVTMQ0wCwYDVQQIDARPaGlvMQ8wDQYDVQQHDAZEYXl0b24xEjAQBgNVBAoM
-CUZvbywgSW5jLjEbMBkGA1UEAwwSbXlob3N0LmxvY2FsZG9tYWluMB4XDTE2MTEy
-NjE3MTUxNFoXDTE2MTIyNjE3MTUxNFowXjELMAkGA1UEBhMCVVMxDTALBgNVBAgM
-BE9oaW8xDzANBgNVBAcMBkRheXRvbjESMBAGA1UECgwJRm9vLCBJbmMuMRswGQYD
-VQQDDBJteWhvc3QubG9jYWxkb21haW4wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
-ggEKAoIBAQDi8OEKkQogjasE908B/yBHqYFtbYfYJJpq3qsxV7oWWLuygEvVTM/O
-edAt0CrXppgh1VxKIbyxkQtf+2TyoUlWxUK/9iYzXolTMQ82X+WeeClPdemoNIYV
-wCKrZObJ1TtBM8v2mL8NfQZumr9NahOfK6pWWuLosKtXviJuzAVKQCm3r0scbzi/
-avSP63LfY/ua7m29PZI4wflLAghAUbNAaefp9UAxgYQigXuIj+lMDhIdfuGEndS+
-xkcW/tqeRr42r4xh1C7lb/FagFqMXA5+wDMn1Tj0JBzQLZMR4Ea2vj24BXuPuA8P
-Kq6wvbpZ4B3k+3jrWNL2i3mPUFFXriP3AgMBAAGjUDBOMB0GA1UdDgQWBBSuHVhn
-CAGxnAE81k3uq1oC+TIRsTAfBgNVHSMEGDAWgBSuHVhnCAGxnAE81k3uq1oC+TIR
-sTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCTk27sW0x9CRPC9ZQs
-FuhhcJQb7KXxhUikctkQC101+xZHE0VZeBLgkHCr8Q1tRzqJuvQO6Q5CRB8b5DIX
-ZHOEtzjNnm8yoMDCWVb/4G8repGacpHDkZv3jZguHxpTYVJlwvdDCr0SGqfpcF4e
-5MY8DgfsmXo2hqKp/FozTA1MKs3esuxdrZBxhvoQpRsvX0mxfiBNoTWVu2BgjeqP
-11vSPK1z2YCxHkt1SvwrpycfGV8x7qNvEIn+zzxPitYJHro0w0WX8aelT7Xtj2mD
-pkLsYhM1dHZkIc+uXVSv+EUUkfLJ1FDJ5D+yyKifyYtBVEOvrDpfUFNKy+bZRYsy
-Lcdy
+MIIDrTCCApWgAwIBAgIUOrrtwPlFPMGGK0ZaGSAKwc7dPwMwDQYJKoZIhvcNAQEL
+BQAwZjELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
+aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxDzANBgNV
+BAMMBmJveXVzYzAeFw0yMDA0MjAxMTEzNDBaFw0yMTA0MjAxMTEzNDBaMGYxCzAJ
+BgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdoYWkx
+DzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMQ8wDQYDVQQDDAZib3l1
+c2MwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEZCIvX4y+wAYIrjAn
+XJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLkCldO
+7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlbp0BT
+NfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gwMUc5
+bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIuiwMf
+y3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfHBJg/
+EQODAgMBAAGjUzBRMB0GA1UdDgQWBBRIZWGS0XoX9JORb2dUGVybYd312DAfBgNV
+HSMEGDAWgBRIZWGS0XoX9JORb2dUGVybYd312DAPBgNVHRMBAf8EBTADAQH/MA0G
+CSqGSIb3DQEBCwUAA4IBAQB09d3fy74u0GYd9AUnGAOjqxG64bQiF3/Z1OOTT3RS
+cQIFTpSDQyw9DfcUXpIqhdD3bnjPkqDlmirPAt1fqJvY1/k3758U1iAvPcqvhyjj
+vDKP+FKHAYFA44YhrUIAadi/g6uuwFVSovzBOE7oefxL5QnBXHSSPBUskdd5GORZ
+PqctPP8ZGtmZkyXRJI8t/rnnhjfnn9XyQkGy5gFdktGoedR7Wf2UDtKxWLv8d4QQ
+SLi2NIJT4nO6oRspQQyBpmBwjbARmMCyfjpO7MQqNsdw7W3LAHb5M3UepidokfoP
+iOYU2Ag2K6QHTsb+PTM8bwVsj2RnvogQn0y3Wvlvxtrp
-----END CERTIFICATE-----
diff --git a/test/server.key.pem b/test/server.key.pem
index 8f7dfc9..1b0799c 100644
--- a/test/server.key.pem
+++ b/test/server.key.pem
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
-MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDi8OEKkQogjasE
-908B/yBHqYFtbYfYJJpq3qsxV7oWWLuygEvVTM/OedAt0CrXppgh1VxKIbyxkQtf
-+2TyoUlWxUK/9iYzXolTMQ82X+WeeClPdemoNIYVwCKrZObJ1TtBM8v2mL8NfQZu
-mr9NahOfK6pWWuLosKtXviJuzAVKQCm3r0scbzi/avSP63LfY/ua7m29PZI4wflL
-AghAUbNAaefp9UAxgYQigXuIj+lMDhIdfuGEndS+xkcW/tqeRr42r4xh1C7lb/Fa
-gFqMXA5+wDMn1Tj0JBzQLZMR4Ea2vj24BXuPuA8PKq6wvbpZ4B3k+3jrWNL2i3mP
-UFFXriP3AgMBAAECggEARjVFOdKjMm0Bkpi8DZ8TKnhrPSJcm2a/iv52Md61CELN
-VqzQSR3pUDRpTjMPfgXhHN54HcsQKFL6FOieU13IZZrDSsXpDY1aqK0NysGiNQNx
-rE6LSelt7f6x+xpNN/XKziIrIJAi0xZxzff75QRDK8QDf5HAj0JQz+VXm7VskYpw
-90YdekO5S/7V8UlLDDQFcKVdsmiPoDogPz6C2CnzD/yVzduJhmoM9PqccRyA/WVD
-YHejPs+LGhM5SLQaMmMWXX5oQ21Gc/t1xvrHokiqcBpxz1djT8I4amRg7D+3bsNG
-d/cRLTKLj1joxJl2VQi+cXT45P5VF5inLwXvraJomQKBgQD0F9FcwhbINjtHFSsr
-gexUjwynvAZyNkI+rROku37wBtT4EwMkRgq9FN6aHZZ8wi6kxRVH7KbmGKXmPkIw
-H/t2lHsae7GZ207H9LZa+VLfDMYCSXa40SvGRBrSPOrTOMCc3HgmP0s/00xfALzs
-T4IHJbOYwhzArZhwC6YLn9byFQKBgQDuAt6QxiJneUM/1JW5P7TEzGLi9bwUmSKH
-EkLbsDKRmqH1EvEoQaG9js9FBLBKaSRYRnub3FbRb7Ckk1MpQY67rOb8L2ypp7uy
-+Bv2Cmbm4mD+/Aapw5Is/6UqNCqTChjI58437eEtZx7X4cYBLwiaKPvPUWI6L2wJ
-4nMsr3fc2wKBgQCpaqqelfvYBIQKJzAqZ2fPnOXsub1DolNCS0CaEqTdFfDVKeUB
-VTf42rZSA31CpEhZhozpueBxTeQ/tTCdVGVlfVMgI4A2SJgagsfaxrf1Jll8lt63
-Ej8uwnBXQX6/EeHmPcOK0F17ND4Kpml6HwkhytInkXsBZLur8PnTkaJPrQKBgQCN
-kF9YtMBZ0yJQoNy85ktakkZuv8IybjK/K/lgOZiaSeLypWWSkBbnbD2Ty4ofeBIJ
-/0IeHhv1Tf0+pfHcpAWFUv3AGWUEM6PMew4GdYFm6lbO0pAUASK8aQGP7J81/ddo
-B5f8ZBx+qMsLlFn08kiniKDdWoaWHQahinL+rQ8Z6QKBgQDN1SpQnFHYy3uugmN0
-KZjDjVs9gBo0lhNVE/HUbf91TiY/ITpjUCHmv+N3VxKyCII4O7+jjFhzK+5NKLV2
-WsYLN9ttR/2FQ4JnTUocXple3DxmaA7rCRZj8ZQ/jrGwbEj5nLyOIDblWgaaADMB
-W2YC7grwofz3HqqSUCHySDHvUA==
+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEZCIvX4y+wAYI
+rjAnXJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLk
+CldO7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlb
+p0BTNfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gw
+MUc5bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIu
+iwMfy3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfH
+BJg/EQODAgMBAAECggEAOLDHBXHJiQ6ZL0xI7jPYmWzHlc4U27wox+vI7x0r+jOo
+BcOZDHuPjge6JYYYnCmixJA8+dhh+TaMyRMLHOdn0LVeb3SxMLzLX9G93d3R/0nM
+AYrJVwxhSZsIC9a7PoT3+GEpnFpkgjEARKrE8MAznNPDDNpAKOQ/WAnYstBUITzN
+7jsct2GQZ1j2acDlH7zsOGiM3nPf1cvg7IVomO3ZlfC0cyo370zDiAZwt88TpzE7
+vLrsVvuIUKbAlmbSzYWx5P5HBeQDFfSbE5iUvkARwZTgMqV9yXqefAitImsSQd4M
+PYATStqYzagj+PgB3PV28IcAS5AGI4G09ieljmJHoQKBgQDn9Usgv/VP33m6RofH
+FHclVcp4J5YNoCQSE3hjIwOg+q0HZieDJSbFxSel+iZSogyw9xxTE3vvG2C3BFwM
+TVAHgodBPAKDcoXgoyTcXTLXfVe6yqfz1zLvXX29qOLbvLlfa9KvDVh9ipGedXxw
+oRMM6nFeRPNQNj/i76dzLxjbuwKBgQDYvx2PXWQqI7mM/aZ07h66t+L5dxyO6lFK
+fOBxkw9IbYE9vY9qVooup1n3WOB6sPbwJfJtFriKh2Uu5rcp+icV1THp0JGnW6mK
+y8oRV1R0+Iq13/IkDKoFgFur3Y3ts219p2rOTI6BDEgkBRaqtJtvOrrky8LYoZxG
+OTFOApMm2QKBgQDQJww7IGeIPLfk1EQl/5SH2Xvu5T8/jPSxj+1ZsWMhQ7KgUCin
+BGDN2wWgaWGYh7kx2R7+4h42TPA2bGAZ3gsyIg00GiD7SnsfQefjJHNqcx2WDyQ2
+qmgX62LaHsMtgycqnPycgDJnvkC83RtFixYoYf5IJUHfOj+Ma5ltwNbi3wKBgBkl
+GtXN/NfSqy0LJCt+kHwS5zcPtXVzA5lDoXormGNLqOmzuxaYEZHWAl7qpag2LX+w
+t04mi6QujvOA+pDZH32t7Qt2Ed+7h5C9kaSvX/Ht/5GX+GxsN7FJsdjfbB6+aR5h
+tMdYJFQeS6Q6HuYQ69Ncmd//L4yYOxv+eJTXQaEJAoGAARX5kUJhSz67fshH6xa6
+oayPo+/RRfehuWiplidBSNG2HYSRkw48/e7BtZ4NQeGMZii3+c6s1Mb9eytdxPdi
+bn+NmO/IogBH3jIZ/gV6u5RXQ+X7YaJ76GaOy7oT+fGmr3Dnbs4wJvs+y5Zq4v/K
+OTUaXDYBXqyjX+afyva87DI=
-----END PRIVATE KEY-----
From e6c988dc97745381317e45bfd7a752b0b5868357 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:20:55 +0800
Subject: [PATCH 084/125] Update package.json
---
package.json | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/package.json b/package.json
index 91c9066..261e916 100644
--- a/package.json
+++ b/package.json
@@ -7,9 +7,8 @@
"scripts": {
"fetch": "node --experimental-modules test/fetch.js",
"open": "node --experimental-modules test/open.js",
- "debug": "node --inspect test/test.js",
"build": "tsc",
- "test": "node --experimental-modules test/test.js",
+ "serve": "node --experimental-modules test/test.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
From a8949661f8f6242e695f61a7575c92266be600dd Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:23:06 +0800
Subject: [PATCH 085/125] =?UTF-8?q?=E6=94=B9=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 2 +-
test/{test.js => serve.js} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename test/{test.js => serve.js} (100%)
mode change 100755 => 100644
diff --git a/package.json b/package.json
index 261e916..bc027f6 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"fetch": "node --experimental-modules test/fetch.js",
"open": "node --experimental-modules test/open.js",
"build": "tsc",
- "serve": "node --experimental-modules test/test.js",
+ "serve": "node --experimental-modules test/serve.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
diff --git a/test/test.js b/test/serve.js
old mode 100755
new mode 100644
similarity index 100%
rename from test/test.js
rename to test/serve.js
From d48b8a5b245ab91d4b0d8b7ea0e21c42692d0d10 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:33:41 +0800
Subject: [PATCH 086/125] =?UTF-8?q?=E6=8A=8Acert=E5=92=8Ckey=E6=8F=90?=
=?UTF-8?q?=E5=8F=96=E5=88=B0=E5=88=86=E5=BC=80=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch.js | 9 ++++++---
test/key-cert.js | 9 +++++++++
test/notfound.js | 12 +++++-------
test/redirect.js | 12 +++++-------
test/simple.js | 11 +++++------
test/websocket.js | 5 +++--
6 files changed, 33 insertions(+), 25 deletions(-)
create mode 100644 test/key-cert.js
diff --git a/test/fetch.js b/test/fetch.js
index c7a248c..1428980 100644
--- a/test/fetch.js
+++ b/test/fetch.js
@@ -1,18 +1,21 @@
import { urls } from "./urls.js";
process.on("unhandledRejection", console.error);
-
+import https from "https";
import fetch1 from "node-fetch";
import fetch2 from "fetch-h2";
-
+import { cert } from "./key-cert.js";
+const agent = new https.Agent({
+ ca: cert,
+});
// @ts-ignore
const fetcharr = [fetch1.default, fetch2.fetch];
Promise.all(
urls
.map((url) =>
fetcharr.map((fetch) => {
- return fetch(url, { redirect: "manual" }).then((r) =>
+ return fetch(url, { redirect: "manual", agent }).then((r) =>
Promise.all([r, r.text()])
);
})
diff --git a/test/key-cert.js b/test/key-cert.js
new file mode 100644
index 0000000..1238f35
--- /dev/null
+++ b/test/key-cert.js
@@ -0,0 +1,9 @@
+import fs from "fs";
+import path from "path";
+import { fileURLToPath } from "url";
+import { dirname } from "path";
+// @ts-ignore
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+export const key = fs.readFileSync(path.join(__dirname, "server.key.pem"));
+export const cert = fs.readFileSync(path.join(__dirname, "server.crt.pem"));
diff --git a/test/notfound.js b/test/notfound.js
index 1b8b0f1..4be8f96 100644
--- a/test/notfound.js
+++ b/test/notfound.js
@@ -1,16 +1,14 @@
+import { dirname } from "path";
+import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
-import fs from "fs";
+import { cert, key } from "./key-cert.js";
const port = 8998;
-import path from "path";
-import { fileURLToPath } from "url";
-import { dirname } from "path";
-
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer({
- key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
+ key,
+ cert,
});
server.listen(port, "localhost", function () {
diff --git a/test/redirect.js b/test/redirect.js
index 8a0c8e7..ec79ed6 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -1,17 +1,15 @@
-import { createServer } from "../lib/index.js";
-import fs from "fs";
-import path from "path";
-import { fileURLToPath } from "url";
import { dirname } from "path";
-
+import { fileURLToPath } from "url";
+import { createServer } from "../lib/index.js";
+import { cert, key } from "./key-cert.js";
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const port = 9001;
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
+ key,
+ cert,
},
function (req, res) {
if ("encrypted" in req.socket) {
diff --git a/test/simple.js b/test/simple.js
index 1bbf630..fab2066 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -1,17 +1,16 @@
+import { dirname } from "path";
+import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
-import fs from "fs";
+import { cert, key } from "./key-cert.js";
const port = 9000;
-import path from "path";
-import { fileURLToPath } from "url";
-import { dirname } from "path";
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
+ key,
+ cert,
},
async function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
diff --git a/test/websocket.js b/test/websocket.js
index 5edde4c..22d5dce 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -5,6 +5,7 @@ import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
import ws from "ws";
+import { cert, key } from "./key-cert.js";
const wsServer = new ws.Server({ noServer: true });
wsServer.on("connection", (websocket, req) => {
websocket.send(JSON.stringify(req.headers));
@@ -17,8 +18,8 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
+ key,
+ cert,
},
async function (req, res) {
if (req.url === "/") {
From ecee2c9e3c2ae979d2f5a2e7a363d57f6cacd021 Mon Sep 17 00:00:00 2001
From: masx200
Date: Mon, 20 Apr 2020 19:37:57 +0800
Subject: [PATCH 087/125] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E8=AF=81=E4=B9=A6?=
=?UTF-8?q?=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
generate-ssl-cert.ps1 | 1 +
server.crt.pem | 22 ++++++++++++++++++++++
server.key.pem | 28 ++++++++++++++++++++++++++++
test/fetch.js | 7 ++++---
test/generate-ssl-cert.ps1 | 1 -
test/server.crt.pem | 22 ----------------------
test/server.key.pem | 28 ----------------------------
7 files changed, 55 insertions(+), 54 deletions(-)
create mode 100644 generate-ssl-cert.ps1
create mode 100644 server.crt.pem
create mode 100644 server.key.pem
delete mode 100644 test/generate-ssl-cert.ps1
delete mode 100644 test/server.crt.pem
delete mode 100644 test/server.key.pem
diff --git a/generate-ssl-cert.ps1 b/generate-ssl-cert.ps1
new file mode 100644
index 0000000..0cb5b7d
--- /dev/null
+++ b/generate-ssl-cert.ps1
@@ -0,0 +1 @@
+openssl req -x509 -days 365 -newkey rsa:2048 -nodes -sha256 -subj "/C=CN/ST=Shanghai/L=Shanghai/O=boyusc/OU=boyusc/CN=localhost" -keyout "server.key.pem" -out "server.crt.pem"
\ No newline at end of file
diff --git a/server.crt.pem b/server.crt.pem
new file mode 100644
index 0000000..b389ac8
--- /dev/null
+++ b/server.crt.pem
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDszCCApugAwIBAgIUMhLSTmO5Dmfk8/R/gD+wZZwANVQwDQYJKoZIhvcNAQEL
+BQAwaTELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
+aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxEjAQBgNV
+BAMMCWxvY2FsaG9zdDAeFw0yMDA0MjAxMTM3MTlaFw0yMTA0MjAxMTM3MTlaMGkx
+CzAJBgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdo
+YWkxDzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMRIwEAYDVQQDDAls
+b2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDAT1n4w0xC
+IArMriVQvLwojioAbl08mqafFGaCpqkeZQrfxpKF95WxY8o4JKEeYgDU8UV3Z60b
+9FpXrT3CQ5KltRP3IRIJYBdotjtYw0vo1dXxXjE67O6sLWbqh9xyqAQB0/NqZRxy
+0AWA2O7zUggJi3a/wWx22aVHPgWOImdZBJdRniSvLPTu/5oadRPdDwHFymZQfTxd
+aiwS2ut1gcU1des3X9C0R7hYHIowXL0T4kGazFn11glrtVTwcvpVS5Zltuqp7/RT
+0ofdcfwOVS6a0v9KP1tMWS9zSqzTMixajMoIDNjEW5fMJisia89G6eeo9pjfrcWb
+MmzHcMpFUPR7AgMBAAGjUzBRMB0GA1UdDgQWBBRZ/0S2wGVN6tdf/io1btyqPDTK
+EjAfBgNVHSMEGDAWgBRZ/0S2wGVN6tdf/io1btyqPDTKEjAPBgNVHRMBAf8EBTAD
+AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQC4pYGWMqiqCxa9sKdJ3/7J8OUfaRkHd0WJ
+fRlcdno1aPMsSFfJqKSl/e/SJYDjMGSQO+U1JUi3+lqhZzj7vD9FNZis/L3674TP
+RGi212v8xBiysXVhgfiNC1k2Yfq7LqQGWFKH7kBDNwdkEPM2HLC0VwcgR9cFL4/K
+YX3TDaNEbeknWUlDonkBkZzVJSCOR9TECdqs8aHTQmbhWa/QuGw5I7d3NHk2VoHV
+dBpyf5dsHcFDW+tinVuKT/DxPJpBB9OCl1grtwHGTV6rgG0UTrn6GoheplFy7sqm
+aKlyZ2X+i+dcZLflULbqM44gFlson6mkG39mgOaTXW3SZAsJBlg9
+-----END CERTIFICATE-----
diff --git a/server.key.pem b/server.key.pem
new file mode 100644
index 0000000..a788464
--- /dev/null
+++ b/server.key.pem
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAT1n4w0xCIArM
+riVQvLwojioAbl08mqafFGaCpqkeZQrfxpKF95WxY8o4JKEeYgDU8UV3Z60b9FpX
+rT3CQ5KltRP3IRIJYBdotjtYw0vo1dXxXjE67O6sLWbqh9xyqAQB0/NqZRxy0AWA
+2O7zUggJi3a/wWx22aVHPgWOImdZBJdRniSvLPTu/5oadRPdDwHFymZQfTxdaiwS
+2ut1gcU1des3X9C0R7hYHIowXL0T4kGazFn11glrtVTwcvpVS5Zltuqp7/RT0ofd
+cfwOVS6a0v9KP1tMWS9zSqzTMixajMoIDNjEW5fMJisia89G6eeo9pjfrcWbMmzH
+cMpFUPR7AgMBAAECggEAaMlUHwZbgRRwjgK99nZAmGCOZlm8mA80hy3YhYxGTneE
+K1bJ9BFqEZRsVZcv65w/E8i7r0pguwC0UV3mbvne6Ef4rwnoCA/B8Z6KS91ueVo7
+Dx/h91eu3UaH83dAGYGPXWeeFPUvQSg0N3b9DLxAAONrOyUr8r65Hk6fPElmwsuY
+jvZxifff11SkaegZD3VMkuYrAgVw7d5ksEAtqeTfjKQ3rbueHC3LrIPp+ngDD5T0
+JPG348PBXOSrXqn6BdRM8BXkMYVG8pM41d8kD+OymfFS3NHYlLa6YWpxRc7Q059S
+dMr+LDM4UB1k/GCnGu0lSjXASVCeoIk76oUVTO4xAQKBgQD1xB+WYYZooSezNg0j
+iLJyswMuxQbKsMGZkPegH31NCJg9UQVVJJyOLqG0hJUmx7HF6lp7lpqxa7hKvgWs
+tzmTJChx8HnmXHPsCbUz3BYkoZZ5gEBt6iXfaZ16G1ZrRzswE5BNWHzKmzBPrXua
+kL/O/s5zPKiLubSmmPZMjY2mOwKBgQDIUWIp4QSTgd8Z7jlDOBXCTPSRXoZo0ZU9
+taBheRHAChWUbAscM9YQcBxCbyjqOB3RQeqSahozgXyLFWIoaZeMeslpdYEQBIQb
+Jw3ZFCcxGpJ4spscxAga8bZa4Fj2AdcKv8Gd6JHgQDfChm7TdjsSFpmRtPb5jbPh
+p4ZSLI/GwQKBgDZrp1L1ZX3lsZTNcztbGaisWxgQKODZIwWOREcAsg5MyOlK95NS
++BfD26rNcPmVXpgkvMSBJOAEqlpimX8VU3pxl0MjrNqFvmWWALnrEjwqS9e7voiY
+QKqoCGbxhsFalJCgxGNcJMX4d0otcCFZzB9Z7P03gVrvVEFPvbpV3ffhAoGBAI/2
+zVHDwgIxCCIer1C78gdePzZqdLbISTW8XrMuy670kGXG8IUoS+QsbmLgeMs74VIO
+yYLIdmQl31gl2hGpMZ1ocXA1XrggRsEs5Crq7O/BZRsRYaDe0eRrat8M9WJ4GBBF
+l+TgzFYaUPignO2kvvdU/rFVGVpomKrINyS/meUBAoGAY7vyXvcdP3wbo3u/Exzu
+RgQy4bvBzvejB1ZePzSxzJUHOliWfjJqM0xqeEWKSZyvVlu9khXGBFD3JklC066j
+LMSkqYJtCMnnrxdCMtvNMfxV7vMxHmMHDv1YLAme0mVlt852d7wmzXDNDRCtYVka
+C42cpJL41oujHaypClQpt/w=
+-----END PRIVATE KEY-----
diff --git a/test/fetch.js b/test/fetch.js
index 1428980..cbd5711 100644
--- a/test/fetch.js
+++ b/test/fetch.js
@@ -15,9 +15,10 @@ Promise.all(
urls
.map((url) =>
fetcharr.map((fetch) => {
- return fetch(url, { redirect: "manual", agent }).then((r) =>
- Promise.all([r, r.text()])
- );
+ return fetch(url, {
+ redirect: "manual",
+ agent: url.startsWith("http:") ? undefined : agent,
+ }).then((r) => Promise.all([r, r.text()]));
})
)
.flat(1 / 0)
diff --git a/test/generate-ssl-cert.ps1 b/test/generate-ssl-cert.ps1
deleted file mode 100644
index 5932dae..0000000
--- a/test/generate-ssl-cert.ps1
+++ /dev/null
@@ -1 +0,0 @@
-openssl req -x509 -days 365 -newkey rsa:2048 -nodes -sha256 -subj "/C=CN/ST=Shanghai/L=Shanghai/O=boyusc/OU=boyusc/CN=boyusc" -keyout "server.key.pem" -out "server.crt.pem"
\ No newline at end of file
diff --git a/test/server.crt.pem b/test/server.crt.pem
deleted file mode 100644
index 38f35a8..0000000
--- a/test/server.crt.pem
+++ /dev/null
@@ -1,22 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDrTCCApWgAwIBAgIUOrrtwPlFPMGGK0ZaGSAKwc7dPwMwDQYJKoZIhvcNAQEL
-BQAwZjELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
-aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxDzANBgNV
-BAMMBmJveXVzYzAeFw0yMDA0MjAxMTEzNDBaFw0yMTA0MjAxMTEzNDBaMGYxCzAJ
-BgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdoYWkx
-DzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMQ8wDQYDVQQDDAZib3l1
-c2MwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEZCIvX4y+wAYIrjAn
-XJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLkCldO
-7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlbp0BT
-NfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gwMUc5
-bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIuiwMf
-y3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfHBJg/
-EQODAgMBAAGjUzBRMB0GA1UdDgQWBBRIZWGS0XoX9JORb2dUGVybYd312DAfBgNV
-HSMEGDAWgBRIZWGS0XoX9JORb2dUGVybYd312DAPBgNVHRMBAf8EBTADAQH/MA0G
-CSqGSIb3DQEBCwUAA4IBAQB09d3fy74u0GYd9AUnGAOjqxG64bQiF3/Z1OOTT3RS
-cQIFTpSDQyw9DfcUXpIqhdD3bnjPkqDlmirPAt1fqJvY1/k3758U1iAvPcqvhyjj
-vDKP+FKHAYFA44YhrUIAadi/g6uuwFVSovzBOE7oefxL5QnBXHSSPBUskdd5GORZ
-PqctPP8ZGtmZkyXRJI8t/rnnhjfnn9XyQkGy5gFdktGoedR7Wf2UDtKxWLv8d4QQ
-SLi2NIJT4nO6oRspQQyBpmBwjbARmMCyfjpO7MQqNsdw7W3LAHb5M3UepidokfoP
-iOYU2Ag2K6QHTsb+PTM8bwVsj2RnvogQn0y3Wvlvxtrp
------END CERTIFICATE-----
diff --git a/test/server.key.pem b/test/server.key.pem
deleted file mode 100644
index 1b0799c..0000000
--- a/test/server.key.pem
+++ /dev/null
@@ -1,28 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDEZCIvX4y+wAYI
-rjAnXJ/bstOfZ0kt1VqVugYMJzsSlo+fKMUHPAB0XcCvz+ilqcJSzYvQjD58VwLk
-CldO7ReFMuVoNlqFnZifiAUw5pW751yvk3Uhqf6embFWExhLIg2omRoVU5zmHrlb
-p0BTNfGdo+0QOqJ7T1QJwluYFmUULqsDZXP8F2j5ctlQdVgHs4KJpFA8fevjd/gw
-MUc5bB9J9DkDU+oswSaA1MQHirSeSqiHUgvxegww2On3aIjbS+mNGJ+rwdZyKbIu
-iwMfy3kxXdmImuk+nWHc5AKWfg61QDJ03WwtkdiRScX1QZnKpNJYMCSuCjeBcSfH
-BJg/EQODAgMBAAECggEAOLDHBXHJiQ6ZL0xI7jPYmWzHlc4U27wox+vI7x0r+jOo
-BcOZDHuPjge6JYYYnCmixJA8+dhh+TaMyRMLHOdn0LVeb3SxMLzLX9G93d3R/0nM
-AYrJVwxhSZsIC9a7PoT3+GEpnFpkgjEARKrE8MAznNPDDNpAKOQ/WAnYstBUITzN
-7jsct2GQZ1j2acDlH7zsOGiM3nPf1cvg7IVomO3ZlfC0cyo370zDiAZwt88TpzE7
-vLrsVvuIUKbAlmbSzYWx5P5HBeQDFfSbE5iUvkARwZTgMqV9yXqefAitImsSQd4M
-PYATStqYzagj+PgB3PV28IcAS5AGI4G09ieljmJHoQKBgQDn9Usgv/VP33m6RofH
-FHclVcp4J5YNoCQSE3hjIwOg+q0HZieDJSbFxSel+iZSogyw9xxTE3vvG2C3BFwM
-TVAHgodBPAKDcoXgoyTcXTLXfVe6yqfz1zLvXX29qOLbvLlfa9KvDVh9ipGedXxw
-oRMM6nFeRPNQNj/i76dzLxjbuwKBgQDYvx2PXWQqI7mM/aZ07h66t+L5dxyO6lFK
-fOBxkw9IbYE9vY9qVooup1n3WOB6sPbwJfJtFriKh2Uu5rcp+icV1THp0JGnW6mK
-y8oRV1R0+Iq13/IkDKoFgFur3Y3ts219p2rOTI6BDEgkBRaqtJtvOrrky8LYoZxG
-OTFOApMm2QKBgQDQJww7IGeIPLfk1EQl/5SH2Xvu5T8/jPSxj+1ZsWMhQ7KgUCin
-BGDN2wWgaWGYh7kx2R7+4h42TPA2bGAZ3gsyIg00GiD7SnsfQefjJHNqcx2WDyQ2
-qmgX62LaHsMtgycqnPycgDJnvkC83RtFixYoYf5IJUHfOj+Ma5ltwNbi3wKBgBkl
-GtXN/NfSqy0LJCt+kHwS5zcPtXVzA5lDoXormGNLqOmzuxaYEZHWAl7qpag2LX+w
-t04mi6QujvOA+pDZH32t7Qt2Ed+7h5C9kaSvX/Ht/5GX+GxsN7FJsdjfbB6+aR5h
-tMdYJFQeS6Q6HuYQ69Ncmd//L4yYOxv+eJTXQaEJAoGAARX5kUJhSz67fshH6xa6
-oayPo+/RRfehuWiplidBSNG2HYSRkw48/e7BtZ4NQeGMZii3+c6s1Mb9eytdxPdi
-bn+NmO/IogBH3jIZ/gV6u5RXQ+X7YaJ76GaOy7oT+fGmr3Dnbs4wJvs+y5Zq4v/K
-OTUaXDYBXqyjX+afyva87DI=
------END PRIVATE KEY-----
From f8014378af0adaf738f156ceab6bc9c841d22124 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 20:21:53 +0800
Subject: [PATCH 088/125] Update key-cert.js
---
test/key-cert.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/key-cert.js b/test/key-cert.js
index 1238f35..ebf1597 100644
--- a/test/key-cert.js
+++ b/test/key-cert.js
@@ -5,5 +5,5 @@ import { dirname } from "path";
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-export const key = fs.readFileSync(path.join(__dirname, "server.key.pem"));
-export const cert = fs.readFileSync(path.join(__dirname, "server.crt.pem"));
+export const key = fs.readFileSync(path.join(__dirname, "../","server.key.pem"));
+export const cert = fs.readFileSync(path.join(__dirname, "../","server.crt.pem"));
From c2b628d1f7992fff6a0586355ccb8a00153240e5 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 20:56:19 +0800
Subject: [PATCH 089/125] Update fetch.js
---
test/fetch.js | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/test/fetch.js b/test/fetch.js
index cbd5711..868c5e3 100644
--- a/test/fetch.js
+++ b/test/fetch.js
@@ -6,20 +6,35 @@ import fetch1 from "node-fetch";
import fetch2 from "fetch-h2";
import { cert } from "./key-cert.js";
-const agent = new https.Agent({
- ca: cert,
-});
+
// @ts-ignore
-const fetcharr = [fetch1.default, fetch2.fetch];
-Promise.all(
- urls
- .map((url) =>
- fetcharr.map((fetch) => {
+
+~((fetch) => {
+ const agent = new https.Agent({
+ ca: cert,
+ });
+ Promise.all(
+ urls
+ .map((url) => {
return fetch(url, {
redirect: "manual",
agent: url.startsWith("http:") ? undefined : agent,
}).then((r) => Promise.all([r, r.text()]));
})
- )
- .flat(1 / 0)
-).then(console.log);
+ .flat(1 / 0)
+ ).then(console.log);
+ // @ts-ignore
+})(fetch1.default);
+
+~((fetch) => {
+ Promise.all(
+ urls
+ .map((url) => {
+ return fetch(url, {
+ redirect: "manual",
+ }).then((r) => Promise.all([r, r.text()]));
+ })
+ .flat(1 / 0)
+ ).then(console.log);
+ // @ts-ignore
+})(fetch2.context({ session: { ca: cert } }).fetch);
From 0746555af3eac0a4ac57d45af43e0c6007fb29c5 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:00:57 +0800
Subject: [PATCH 090/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/declaration.d.ts | 26 +++++-----------------
lib/index.d.ts | 12 ++--------
lib/index.js | 19 ++++++++--------
server.crt.pem | 32 +++++++++++++--------------
server.key.pem | 52 ++++++++++++++++++++++----------------------
test/key-cert.js | 5 +++--
6 files changed, 61 insertions(+), 85 deletions(-)
diff --git a/lib/declaration.d.ts b/lib/declaration.d.ts
index 490a601..52af6da 100644
--- a/lib/declaration.d.ts
+++ b/lib/declaration.d.ts
@@ -19,28 +19,12 @@ export interface ServerResponse extends http.ServerResponse {
push?: (pathname: string, options?: PushOptions) => stream.Writable;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (
- req: ServerRequest,
- res: ServerResponse
-) => void;
-export declare type UpgradeListener = (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
+export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
+export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
export declare type ServerOptions = spdy.ServerOptions & {
allowHalfOpen?: boolean | undefined;
pauseOnConnect?: boolean | undefined;
-} & http.ServerOptions &
- tls.TlsOptions &
- https.ServerOptions;
-export declare const requestNotFound: (
- req: ServerRequest,
- res: ServerResponse
-) => void;
-export declare const upgradeNotFound: (
- req: ServerRequest,
- socket: Socket,
- head: Buffer
-) => void;
+} & http.ServerOptions & tls.TlsOptions & https.ServerOptions;
+export declare const requestNotFound: (req: ServerRequest, res: ServerResponse) => void;
+export declare const upgradeNotFound: (req: ServerRequest, socket: Socket, head: Buffer) => void;
export {};
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 106f240..9e27f52 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,14 +1,6 @@
///
import net from "net";
-import {
- RequestListener,
- ServerOptions,
- UpgradeListener,
-} from "./declaration.js";
+import { RequestListener, ServerOptions, UpgradeListener } from "./declaration.js";
export * from "./declaration.js";
export { createServer };
-declare function createServer(
- config: ServerOptions,
- requestListener?: RequestListener,
- upgradeListener?: UpgradeListener
-): net.Server;
+declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): net.Server;
diff --git a/lib/index.js b/lib/index.js
index 93fc140..228d47b 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,14 +1,10 @@
import http from "http";
import net from "net";
import spdy from "spdy";
-import { requestNotFound, upgradeNotFound } from "./declaration.js";
+import { requestNotFound, upgradeNotFound, } from "./declaration.js";
export * from "./declaration.js";
export { createServer };
-function createServer(
- config,
- requestListener = requestNotFound,
- upgradeListener = upgradeNotFound
-) {
+function createServer(config, requestListener = requestNotFound, upgradeListener = upgradeNotFound) {
if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
@@ -28,21 +24,24 @@ function createServer(
servernet.addListener("connection", connectionListener);
function connectionListener(socket) {
if (!socket.listeners("error").length) {
- socket.on("error", function () {});
+ socket.on("error", function () { });
}
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- } else {
+ }
+ else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- } else if (32 < firstByte && firstByte < 127) {
+ }
+ else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- } else {
+ }
+ else {
socket.destroy();
}
}
diff --git a/server.crt.pem b/server.crt.pem
index b389ac8..a6c8f1c 100644
--- a/server.crt.pem
+++ b/server.crt.pem
@@ -1,22 +1,22 @@
-----BEGIN CERTIFICATE-----
-MIIDszCCApugAwIBAgIUMhLSTmO5Dmfk8/R/gD+wZZwANVQwDQYJKoZIhvcNAQEL
+MIIDszCCApugAwIBAgIUR48GNH+FtTTJpeoE06dMGncARAcwDQYJKoZIhvcNAQEL
BQAwaTELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxEjAQBgNV
-BAMMCWxvY2FsaG9zdDAeFw0yMDA0MjAxMTM3MTlaFw0yMTA0MjAxMTM3MTlaMGkx
+BAMMCWxvY2FsaG9zdDAeFw0yMDA0MjAxMzAwNDJaFw0yMTA0MjAxMzAwNDJaMGkx
CzAJBgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdo
YWkxDzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMRIwEAYDVQQDDAls
-b2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDAT1n4w0xC
-IArMriVQvLwojioAbl08mqafFGaCpqkeZQrfxpKF95WxY8o4JKEeYgDU8UV3Z60b
-9FpXrT3CQ5KltRP3IRIJYBdotjtYw0vo1dXxXjE67O6sLWbqh9xyqAQB0/NqZRxy
-0AWA2O7zUggJi3a/wWx22aVHPgWOImdZBJdRniSvLPTu/5oadRPdDwHFymZQfTxd
-aiwS2ut1gcU1des3X9C0R7hYHIowXL0T4kGazFn11glrtVTwcvpVS5Zltuqp7/RT
-0ofdcfwOVS6a0v9KP1tMWS9zSqzTMixajMoIDNjEW5fMJisia89G6eeo9pjfrcWb
-MmzHcMpFUPR7AgMBAAGjUzBRMB0GA1UdDgQWBBRZ/0S2wGVN6tdf/io1btyqPDTK
-EjAfBgNVHSMEGDAWgBRZ/0S2wGVN6tdf/io1btyqPDTKEjAPBgNVHRMBAf8EBTAD
-AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQC4pYGWMqiqCxa9sKdJ3/7J8OUfaRkHd0WJ
-fRlcdno1aPMsSFfJqKSl/e/SJYDjMGSQO+U1JUi3+lqhZzj7vD9FNZis/L3674TP
-RGi212v8xBiysXVhgfiNC1k2Yfq7LqQGWFKH7kBDNwdkEPM2HLC0VwcgR9cFL4/K
-YX3TDaNEbeknWUlDonkBkZzVJSCOR9TECdqs8aHTQmbhWa/QuGw5I7d3NHk2VoHV
-dBpyf5dsHcFDW+tinVuKT/DxPJpBB9OCl1grtwHGTV6rgG0UTrn6GoheplFy7sqm
-aKlyZ2X+i+dcZLflULbqM44gFlson6mkG39mgOaTXW3SZAsJBlg9
+b2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpuS0fAr08
+OrjWYFKzkemcWgHVd8nsyYPUORm4Ctw/Np93YJzzSe38Gy6G6frD5iQIGzbWaMm8
+tDEHpf2eNxAO2F2ASx3wg2IkHxDQ2dbaxLL/NupgpQDcbZgJEzgHXK1kX7Pa5Jkp
+czh9u5Av9phACulYaIgIvIUHB70eJ2nHjqplAWDCv1utcgKCeBPZS/hk+E5wckv/
+wFomBu+P0R/vTNOH9plXQSZulorjxGkTYD4X1oeyaA3V8UOTie+aEnoXdwI+pTSq
+M6mGM8CKpOngxrHzmPNv3P70ncn04BN81ljYJ3z8ot6NxM9+1wcf5CXqo066UmgD
+GGY1GH85VQrLAgMBAAGjUzBRMB0GA1UdDgQWBBSacHb7ensjgNErYHmJNoZW4kbq
+WjAfBgNVHSMEGDAWgBSacHb7ensjgNErYHmJNoZW4kbqWjAPBgNVHRMBAf8EBTAD
+AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAg+Pr2lKVdGlCqSVW62wh6X+YpkWN7rIbG
+lDRuBL6vrGZYFaJrWAGfjD3x3pgYf7S3APxOPjs3ihO5Pxh2btk856GP7RIed7Ho
+Q31VSzLUl75u6ytCJF6pFZKaGP+T8WqF3rpEqo5fJebzEFCgloKpJxuwPN+tcEhQ
+WcdaDJuaspOTTKr0buARZybj86cCdH/R9zr0n9sDzqWIBnJ1dd22BV0UwVSamdTe
+b2ENZYAKbX5Yto9KCFwLWphYK8IS1zQX0QdFYoVDlyroI99fgQdGOthUXImvZuZv
+CRgSrRakQvAzCBXG1uaPajdRIATJDGlQmx4/e4Do9sG3V1BTt67P
-----END CERTIFICATE-----
diff --git a/server.key.pem b/server.key.pem
index a788464..389d948 100644
--- a/server.key.pem
+++ b/server.key.pem
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
-MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAT1n4w0xCIArM
-riVQvLwojioAbl08mqafFGaCpqkeZQrfxpKF95WxY8o4JKEeYgDU8UV3Z60b9FpX
-rT3CQ5KltRP3IRIJYBdotjtYw0vo1dXxXjE67O6sLWbqh9xyqAQB0/NqZRxy0AWA
-2O7zUggJi3a/wWx22aVHPgWOImdZBJdRniSvLPTu/5oadRPdDwHFymZQfTxdaiwS
-2ut1gcU1des3X9C0R7hYHIowXL0T4kGazFn11glrtVTwcvpVS5Zltuqp7/RT0ofd
-cfwOVS6a0v9KP1tMWS9zSqzTMixajMoIDNjEW5fMJisia89G6eeo9pjfrcWbMmzH
-cMpFUPR7AgMBAAECggEAaMlUHwZbgRRwjgK99nZAmGCOZlm8mA80hy3YhYxGTneE
-K1bJ9BFqEZRsVZcv65w/E8i7r0pguwC0UV3mbvne6Ef4rwnoCA/B8Z6KS91ueVo7
-Dx/h91eu3UaH83dAGYGPXWeeFPUvQSg0N3b9DLxAAONrOyUr8r65Hk6fPElmwsuY
-jvZxifff11SkaegZD3VMkuYrAgVw7d5ksEAtqeTfjKQ3rbueHC3LrIPp+ngDD5T0
-JPG348PBXOSrXqn6BdRM8BXkMYVG8pM41d8kD+OymfFS3NHYlLa6YWpxRc7Q059S
-dMr+LDM4UB1k/GCnGu0lSjXASVCeoIk76oUVTO4xAQKBgQD1xB+WYYZooSezNg0j
-iLJyswMuxQbKsMGZkPegH31NCJg9UQVVJJyOLqG0hJUmx7HF6lp7lpqxa7hKvgWs
-tzmTJChx8HnmXHPsCbUz3BYkoZZ5gEBt6iXfaZ16G1ZrRzswE5BNWHzKmzBPrXua
-kL/O/s5zPKiLubSmmPZMjY2mOwKBgQDIUWIp4QSTgd8Z7jlDOBXCTPSRXoZo0ZU9
-taBheRHAChWUbAscM9YQcBxCbyjqOB3RQeqSahozgXyLFWIoaZeMeslpdYEQBIQb
-Jw3ZFCcxGpJ4spscxAga8bZa4Fj2AdcKv8Gd6JHgQDfChm7TdjsSFpmRtPb5jbPh
-p4ZSLI/GwQKBgDZrp1L1ZX3lsZTNcztbGaisWxgQKODZIwWOREcAsg5MyOlK95NS
-+BfD26rNcPmVXpgkvMSBJOAEqlpimX8VU3pxl0MjrNqFvmWWALnrEjwqS9e7voiY
-QKqoCGbxhsFalJCgxGNcJMX4d0otcCFZzB9Z7P03gVrvVEFPvbpV3ffhAoGBAI/2
-zVHDwgIxCCIer1C78gdePzZqdLbISTW8XrMuy670kGXG8IUoS+QsbmLgeMs74VIO
-yYLIdmQl31gl2hGpMZ1ocXA1XrggRsEs5Crq7O/BZRsRYaDe0eRrat8M9WJ4GBBF
-l+TgzFYaUPignO2kvvdU/rFVGVpomKrINyS/meUBAoGAY7vyXvcdP3wbo3u/Exzu
-RgQy4bvBzvejB1ZePzSxzJUHOliWfjJqM0xqeEWKSZyvVlu9khXGBFD3JklC066j
-LMSkqYJtCMnnrxdCMtvNMfxV7vMxHmMHDv1YLAme0mVlt852d7wmzXDNDRCtYVka
-C42cpJL41oujHaypClQpt/w=
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCpuS0fAr08OrjW
+YFKzkemcWgHVd8nsyYPUORm4Ctw/Np93YJzzSe38Gy6G6frD5iQIGzbWaMm8tDEH
+pf2eNxAO2F2ASx3wg2IkHxDQ2dbaxLL/NupgpQDcbZgJEzgHXK1kX7Pa5Jkpczh9
+u5Av9phACulYaIgIvIUHB70eJ2nHjqplAWDCv1utcgKCeBPZS/hk+E5wckv/wFom
+Bu+P0R/vTNOH9plXQSZulorjxGkTYD4X1oeyaA3V8UOTie+aEnoXdwI+pTSqM6mG
+M8CKpOngxrHzmPNv3P70ncn04BN81ljYJ3z8ot6NxM9+1wcf5CXqo066UmgDGGY1
+GH85VQrLAgMBAAECggEALnkG8tvUJx7JJ+IeIw9MEUTQBbyULOMM1tp/wVYv8psp
+VQ2+TButL3/d4JFG2cc1jIavIEx3GNWaK0b3SBA5tGboS03GN+oxwERFXXqYizSa
+8qj9ylLEBpd3rtx1Vga5b6eI3uIDUkc7a6olFA0IqViThmKxBPthzYf/77bJDxv+
+P9goEfsOJCNjogDCrM5g9inDfQ1L6yxFngmn/R4R6RrdBUk9pmOK+i8hrrVsAVzr
+9qfMumwf2y6Hc/t+b+7cvG9yIYH26oZuMnqsAZnGRfzVXkOTFEbq8yo8UqTIRoB9
+D0p8GoLFQXNgBwRYtLvQ+6F62cHjmJZWxlqawNMEgQKBgQDTrPYGViNaSyPdf4JQ
+y8IZpsLCZV3NBzk+Wk6KUEnN0BTnulK63oA176xOG+3MeUlItpJylLcKSzHUcc/k
+6eihFDIiPco8MCLROcEMvqXwGy1mM+BTdJQAYTWzT5NutNhzn5emBFwONF99OWLu
+1TqnFy6v+nrPAImIv5jfOBZTCwKBgQDNQ1R3e1R16y2bhr3xw+0bPJC9NLX09ObK
+2N6Vrw7RK7fw0p16lndzdbZE23sZwkqyKlw2+teZUHsQMyG75Ffx/OsMpEh7s3dr
+iZCNwqQIbR7nh7qLwTkroEWO6IEOs2jaOaNoI4hIcy3rn4lpdoWinM+WGdWqsVul
+SNr7VBb/QQKBgGcUxJ6jVgYDr4yPKrwD7hslzZRzXrGYwfSub68FmFtk6LlMUDt2
+XUNm2ycSjMRVkC2b00d/Sn/1zGdjoVUd386JkjyAkLqsylfPY0a8lPyPj5VE0Ap0
+LBrfPBJ9PxPbd8kev+/2EYpNUO8fgiFCr5RtQqwqM6IY5eE1RNH3c0+vAoGBAIgv
+tekYQK+D+9yGh5vSnIxHoNiIEnmVy1KmlPfHEBOj6AS2GJnvHw3R+b6xyHkMubZ/
++HLZ9xXXme7jnewl0lvRrLnUferk5cTJnskPbPnSPIDtQs3aw224hq4MgSQZ0OWI
+/Gvpt1Aqazs7vFXmtz9uvyQdu+/mgKGnNvMtlZyBAoGBAMIx5crrxOwyGSohdDJr
+iQCmt3SVStmE82XDh8LpK13+iQyPjJ9emDBg5G6iyyf7xMoZxcFW7p3faH/davPF
+aP2HXSP1HAS3Bf7y7+rBF7uSvGgBZiQLb7N4a5k9geDSkNDi0z0nHUO6m5JC36/J
+8tuDzk8Zr5U9TBgx4NjV4hib
-----END PRIVATE KEY-----
diff --git a/test/key-cert.js b/test/key-cert.js
index ebf1597..5eec16f 100644
--- a/test/key-cert.js
+++ b/test/key-cert.js
@@ -5,5 +5,6 @@ import { dirname } from "path";
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-export const key = fs.readFileSync(path.join(__dirname, "../","server.key.pem"));
-export const cert = fs.readFileSync(path.join(__dirname, "../","server.crt.pem"));
+
+export const key = fs.readFileSync(path.join(__dirname, "../","./server.key.pem"));
+export const cert = fs.readFileSync(path.join(__dirname, "../","./server.crt.pem"));
From 3ba5993ba8d40147a887386cf05f9f02d816e5ba Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:02:29 +0800
Subject: [PATCH 091/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/declaration.d.ts | 26 +++++++++++++++++++++-----
lib/index.d.ts | 12 ++++++++++--
lib/index.js | 19 ++++++++++---------
test/key-cert.js | 8 ++++++--
test/push.js | 12 +++++-------
5 files changed, 52 insertions(+), 25 deletions(-)
diff --git a/lib/declaration.d.ts b/lib/declaration.d.ts
index 52af6da..490a601 100644
--- a/lib/declaration.d.ts
+++ b/lib/declaration.d.ts
@@ -19,12 +19,28 @@ export interface ServerResponse extends http.ServerResponse {
push?: (pathname: string, options?: PushOptions) => stream.Writable;
}
export declare type Socket = Partial & net.Socket;
-export declare type RequestListener = (req: ServerRequest, res: ServerResponse) => void;
-export declare type UpgradeListener = (req: ServerRequest, socket: Socket, head: Buffer) => void;
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
export declare type ServerOptions = spdy.ServerOptions & {
allowHalfOpen?: boolean | undefined;
pauseOnConnect?: boolean | undefined;
-} & http.ServerOptions & tls.TlsOptions & https.ServerOptions;
-export declare const requestNotFound: (req: ServerRequest, res: ServerResponse) => void;
-export declare const upgradeNotFound: (req: ServerRequest, socket: Socket, head: Buffer) => void;
+} & http.ServerOptions &
+ tls.TlsOptions &
+ https.ServerOptions;
+export declare const requestNotFound: (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+export declare const upgradeNotFound: (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
export {};
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 9e27f52..106f240 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -1,6 +1,14 @@
///
import net from "net";
-import { RequestListener, ServerOptions, UpgradeListener } from "./declaration.js";
+import {
+ RequestListener,
+ ServerOptions,
+ UpgradeListener,
+} from "./declaration.js";
export * from "./declaration.js";
export { createServer };
-declare function createServer(config: ServerOptions, requestListener?: RequestListener, upgradeListener?: UpgradeListener): net.Server;
+declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): net.Server;
diff --git a/lib/index.js b/lib/index.js
index 228d47b..93fc140 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,10 +1,14 @@
import http from "http";
import net from "net";
import spdy from "spdy";
-import { requestNotFound, upgradeNotFound, } from "./declaration.js";
+import { requestNotFound, upgradeNotFound } from "./declaration.js";
export * from "./declaration.js";
export { createServer };
-function createServer(config, requestListener = requestNotFound, upgradeListener = upgradeNotFound) {
+function createServer(
+ config,
+ requestListener = requestNotFound,
+ upgradeListener = upgradeNotFound
+) {
if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
@@ -24,24 +28,21 @@ function createServer(config, requestListener = requestNotFound, upgradeListener
servernet.addListener("connection", connectionListener);
function connectionListener(socket) {
if (!socket.listeners("error").length) {
- socket.on("error", function () { });
+ socket.on("error", function () {});
}
const data = socket.read(1);
if (data === null) {
socket.once("readable", () => {
connectionListener(socket);
});
- }
- else {
+ } else {
const firstByte = data[0];
socket.unshift(data);
if (firstByte === 22) {
handletls(socket);
- }
- else if (32 < firstByte && firstByte < 127) {
+ } else if (32 < firstByte && firstByte < 127) {
handlehttp(socket);
- }
- else {
+ } else {
socket.destroy();
}
}
diff --git a/test/key-cert.js b/test/key-cert.js
index 5eec16f..5b01d2b 100644
--- a/test/key-cert.js
+++ b/test/key-cert.js
@@ -6,5 +6,9 @@ import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
-export const key = fs.readFileSync(path.join(__dirname, "../","./server.key.pem"));
-export const cert = fs.readFileSync(path.join(__dirname, "../","./server.crt.pem"));
+export const key = fs.readFileSync(
+ path.join(__dirname, "../", "./server.key.pem")
+);
+export const cert = fs.readFileSync(
+ path.join(__dirname, "../", "./server.crt.pem")
+);
diff --git a/test/push.js b/test/push.js
index 559492f..968622d 100644
--- a/test/push.js
+++ b/test/push.js
@@ -1,17 +1,15 @@
+import { dirname } from "path";
+import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
-import fs from "fs";
+import { cert, key } from "./key-cert.js";
const port = 9002;
-import path from "path";
-import { fileURLToPath } from "url";
-import { dirname } from "path";
-
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = createServer(
{
- key: fs.readFileSync(path.join(__dirname, "server.key.pem")),
- cert: fs.readFileSync(path.join(__dirname, "server.crt.pem")),
+ key,
+ cert,
},
(req, res) => {
if (req.url == "/main.js") {
From a63ea6e6d76e87a8beeee2f523a6c0d4de9a8a4b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:05:52 +0800
Subject: [PATCH 092/125] =?UTF-8?q?=E6=8B=86=E5=88=86=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 6 +++---
test/{fetch.js => fetch1.js} | 19 +++----------------
test/fetch2.js | 21 +++++++++++++++++++++
3 files changed, 27 insertions(+), 19 deletions(-)
rename test/{fetch.js => fetch1.js} (63%)
create mode 100644 test/fetch2.js
diff --git a/package.json b/package.json
index bc027f6..ae42e2f 100644
--- a/package.json
+++ b/package.json
@@ -5,10 +5,10 @@
"version": "1.0.0",
"main": "./lib/index.js",
"scripts": {
- "fetch": "node --experimental-modules test/fetch.js",
- "open": "node --experimental-modules test/open.js",
+ "fetch": "node --experimental-modules ./test/fetch1.js && node --experimental-modules ./test/fetch2.js",
+ "open": "node --experimental-modules ./test/open.js",
"build": "tsc",
- "serve": "node --experimental-modules test/serve.js",
+ "serve": "node --experimental-modules ./test/serve.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
"engines": {
diff --git a/test/fetch.js b/test/fetch1.js
similarity index 63%
rename from test/fetch.js
rename to test/fetch1.js
index 868c5e3..23f7d35 100644
--- a/test/fetch.js
+++ b/test/fetch1.js
@@ -1,11 +1,10 @@
+import https from "https";
+import fetch1 from "node-fetch";
+import { cert } from "./key-cert.js";
import { urls } from "./urls.js";
process.on("unhandledRejection", console.error);
-import https from "https";
-import fetch1 from "node-fetch";
-import fetch2 from "fetch-h2";
-import { cert } from "./key-cert.js";
// @ts-ignore
@@ -26,15 +25,3 @@ import { cert } from "./key-cert.js";
// @ts-ignore
})(fetch1.default);
-~((fetch) => {
- Promise.all(
- urls
- .map((url) => {
- return fetch(url, {
- redirect: "manual",
- }).then((r) => Promise.all([r, r.text()]));
- })
- .flat(1 / 0)
- ).then(console.log);
- // @ts-ignore
-})(fetch2.context({ session: { ca: cert } }).fetch);
diff --git a/test/fetch2.js b/test/fetch2.js
new file mode 100644
index 0000000..2423884
--- /dev/null
+++ b/test/fetch2.js
@@ -0,0 +1,21 @@
+import fetch2 from "fetch-h2";
+import { cert } from "./key-cert.js";
+import { urls } from "./urls.js";
+
+process.on("unhandledRejection", console.error);
+
+
+// @ts-ignore
+
+~((fetch) => {
+ Promise.all(
+ urls
+ .map((url) => {
+ return fetch(url, {
+ redirect: "manual",
+ }).then((r) => Promise.all([r, r.text()]));
+ })
+ .flat(1 / 0)
+ ).then(console.log);
+ // @ts-ignore
+})(fetch2.context({ session: { ca: cert } }).fetch);
From 415982cfbbefdc37ce613944ac3fab7896f678c0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:09:59 +0800
Subject: [PATCH 093/125] =?UTF-8?q?=E9=87=8D=E6=9E=84fetch?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 3 ++-
test/fetch1.js | 22 ++++++++++++++++------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/package.json b/package.json
index ae42e2f..bfb2794 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,8 @@
"version": "1.0.0",
"main": "./lib/index.js",
"scripts": {
- "fetch": "node --experimental-modules ./test/fetch1.js && node --experimental-modules ./test/fetch2.js",
+ "fetch1": "node --experimental-modules ./test/fetch1.js ",
+ "fetch2": " node --experimental-modules ./test/fetch2.js",
"open": "node --experimental-modules ./test/open.js",
"build": "tsc",
"serve": "node --experimental-modules ./test/serve.js",
diff --git a/test/fetch1.js b/test/fetch1.js
index 23f7d35..f40fa65 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -5,23 +5,33 @@ import { urls } from "./urls.js";
process.on("unhandledRejection", console.error);
+const fetch =
+ /**
+ * @param {string} url
+ * @param {Object} opt
+ */
+ function (url, opt) {
+ const agent = new https.Agent({
+ ca: cert,
+ });
+ // @ts-ignore
+ return fetch1.default(url, {
+ agent: url.startsWith("http:") ? undefined : agent,
+ ...opt,
+ });
+ };
// @ts-ignore
~((fetch) => {
- const agent = new https.Agent({
- ca: cert,
- });
Promise.all(
urls
.map((url) => {
return fetch(url, {
redirect: "manual",
- agent: url.startsWith("http:") ? undefined : agent,
}).then((r) => Promise.all([r, r.text()]));
})
.flat(1 / 0)
).then(console.log);
// @ts-ignore
-})(fetch1.default);
-
+})(fetch);
From 7d1969e4abd965157c2951e803ca0381975e5cb0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:12:28 +0800
Subject: [PATCH 094/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 5 +++--
test/logjson.js | 6 ++++++
2 files changed, 9 insertions(+), 2 deletions(-)
create mode 100644 test/logjson.js
diff --git a/test/fetch1.js b/test/fetch1.js
index f40fa65..7d60f5b 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -2,6 +2,7 @@ import https from "https";
import fetch1 from "node-fetch";
import { cert } from "./key-cert.js";
import { urls } from "./urls.js";
+import { logjson } from "./logjson.js";
process.on("unhandledRejection", console.error);
@@ -29,9 +30,9 @@ const fetch =
.map((url) => {
return fetch(url, {
redirect: "manual",
- }).then((r) => Promise.all([r, r.text()]));
+ }).then((r) => Promise.all([r.status,[...r.headers], r.text()]));
})
.flat(1 / 0)
- ).then(console.log);
+ ).then(logjson);
// @ts-ignore
})(fetch);
diff --git a/test/logjson.js b/test/logjson.js
new file mode 100644
index 0000000..fb1cee0
--- /dev/null
+++ b/test/logjson.js
@@ -0,0 +1,6 @@
+/**
+ * @param {any} o
+ */
+export function logjson(o){
+ console.log(JSON.stringify(o,null,4))
+}
\ No newline at end of file
From 014688330281cd901b97622718d6156629135db1 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:20:39 +0800
Subject: [PATCH 095/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 4 +++-
test/fetch2.js | 1 -
test/format-response.js | 6 ++++++
test/logjson.js | 6 +++---
4 files changed, 12 insertions(+), 5 deletions(-)
create mode 100644 test/format-response.js
diff --git a/test/fetch1.js b/test/fetch1.js
index 7d60f5b..79690b2 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -3,6 +3,7 @@ import fetch1 from "node-fetch";
import { cert } from "./key-cert.js";
import { urls } from "./urls.js";
import { logjson } from "./logjson.js";
+import { formatresponse } from "./format-response.js";
process.on("unhandledRejection", console.error);
@@ -30,8 +31,9 @@ const fetch =
.map((url) => {
return fetch(url, {
redirect: "manual",
- }).then((r) => Promise.all([r.status,[...r.headers], r.text()]));
+ }).then((r) => formatresponse(r));
})
+
.flat(1 / 0)
).then(logjson);
// @ts-ignore
diff --git a/test/fetch2.js b/test/fetch2.js
index 2423884..44dbf51 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -4,7 +4,6 @@ import { urls } from "./urls.js";
process.on("unhandledRejection", console.error);
-
// @ts-ignore
~((fetch) => {
diff --git a/test/format-response.js b/test/format-response.js
new file mode 100644
index 0000000..199c18a
--- /dev/null
+++ b/test/format-response.js
@@ -0,0 +1,6 @@
+/**
+ * @param {{ url: any; status: any; headers: any; text: () => any; }} r
+ */
+export function formatresponse(r) {
+ return Promise.all([r.url, r.status, [...r.headers], r.text()]);
+}
diff --git a/test/logjson.js b/test/logjson.js
index fb1cee0..e62fd96 100644
--- a/test/logjson.js
+++ b/test/logjson.js
@@ -1,6 +1,6 @@
/**
* @param {any} o
*/
-export function logjson(o){
- console.log(JSON.stringify(o,null,4))
-}
\ No newline at end of file
+export function logjson(o) {
+ console.log(JSON.stringify(o, null, 4));
+}
From 7b8f17adfbddcc153b9499b2846147b3d7f97b34 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:30:05 +0800
Subject: [PATCH 096/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 10 ++++++----
test/fetch2.js | 21 +++++++++++++++------
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/test/fetch1.js b/test/fetch1.js
index 79690b2..6b9eb0f 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -26,12 +26,14 @@ const fetch =
// @ts-ignore
~((fetch) => {
- Promise.all(
+ Promise.allSettled(
urls
.map((url) => {
- return fetch(url, {
- redirect: "manual",
- }).then((r) => formatresponse(r));
+ return fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ );
})
.flat(1 / 0)
diff --git a/test/fetch2.js b/test/fetch2.js
index 44dbf51..2ab7fed 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -1,20 +1,29 @@
import fetch2 from "fetch-h2";
import { cert } from "./key-cert.js";
import { urls } from "./urls.js";
+import { formatresponse } from "./format-response.js";
+import { logjson } from "./logjson.js";
process.on("unhandledRejection", console.error);
+const fetch = fetch2.context({ session: { ca: cert } }).fetch;
+
// @ts-ignore
~((fetch) => {
- Promise.all(
+ Promise.allSettled(
+ /**
+ * @param {string | fetch2.Request} url
+ */
urls
.map((url) => {
- return fetch(url, {
- redirect: "manual",
- }).then((r) => Promise.all([r, r.text()]));
+ return fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ );
})
.flat(1 / 0)
- ).then(console.log);
+ ).then(logjson);
// @ts-ignore
-})(fetch2.context({ session: { ca: cert } }).fetch);
+})(fetch);
From 8707ff1f00c40555a82e396c92b607a93945a0bb Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:32:12 +0800
Subject: [PATCH 097/125] Update fetch2.js
---
test/fetch2.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/fetch2.js b/test/fetch2.js
index 2ab7fed..6a88ed6 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -17,6 +17,7 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
*/
urls
.map((url) => {
+
return fetch(url, { timeout: 2000, redirect: "manual" }).then(
(r) => {
return formatresponse(r);
From ec1a029c0459b964a129c3cdf1e33b199ff34f2b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:34:29 +0800
Subject: [PATCH 098/125] Update fetch2.js
---
test/fetch2.js | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/test/fetch2.js b/test/fetch2.js
index 6a88ed6..9e48581 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -17,12 +17,17 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
*/
urls
.map((url) => {
-
- return fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
- return formatresponse(r);
- }
- );
+ return new Promise((resolve, reject) => {
+ setTimeout(() => reject(new Error("timeout")), 2000);
+
+ resolve(
+ fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ )
+ );
+ });
})
.flat(1 / 0)
).then(logjson);
From c526ccaddbf1ec1f2032b464f28c4345701a47e0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:36:04 +0800
Subject: [PATCH 099/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 2 +-
test/fetch2.js | 26 ++++++++++++--------------
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/test/fetch1.js b/test/fetch1.js
index 6b9eb0f..93ec1c9 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -36,7 +36,7 @@ const fetch =
);
})
- .flat(1 / 0)
+
).then(logjson);
// @ts-ignore
})(fetch);
diff --git a/test/fetch2.js b/test/fetch2.js
index 9e48581..8c0b940 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -15,21 +15,19 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
/**
* @param {string | fetch2.Request} url
*/
- urls
- .map((url) => {
- return new Promise((resolve, reject) => {
- setTimeout(() => reject(new Error("timeout")), 2000);
+ urls.map((url) => {
+ return new Promise((resolve, reject) => {
+ setTimeout(() => reject(new Error("timeout")), 2000);
- resolve(
- fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
- return formatresponse(r);
- }
- )
- );
- });
- })
- .flat(1 / 0)
+ resolve(
+ fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ )
+ );
+ });
+ })
).then(logjson);
// @ts-ignore
})(fetch);
From a40c30d0fcd5178f4f71e4a36985c0d34bc18bc9 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:39:13 +0800
Subject: [PATCH 100/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 17 +++++++----------
test/fetch2.js | 19 +++++--------------
2 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/test/fetch1.js b/test/fetch1.js
index 93ec1c9..48dc896 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -27,16 +27,13 @@ const fetch =
~((fetch) => {
Promise.allSettled(
- urls
- .map((url) => {
- return fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
- return formatresponse(r);
- }
- );
- })
-
-
+ urls.map((url) => {
+ return fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ );
+ })
).then(logjson);
// @ts-ignore
})(fetch);
diff --git a/test/fetch2.js b/test/fetch2.js
index 8c0b940..ae617dc 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -12,21 +12,12 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
~((fetch) => {
Promise.allSettled(
- /**
- * @param {string | fetch2.Request} url
- */
urls.map((url) => {
- return new Promise((resolve, reject) => {
- setTimeout(() => reject(new Error("timeout")), 2000);
-
- resolve(
- fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
- return formatresponse(r);
- }
- )
- );
- });
+ return fetch(url, { timeout: 2000, redirect: "manual" }).then(
+ (r) => {
+ return formatresponse(r);
+ }
+ );
})
).then(logjson);
// @ts-ignore
From 1a3d08678d0a370a1e4cc9fc22b57921aa8da936 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:42:23 +0800
Subject: [PATCH 101/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 2 +-
test/fetch2.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/fetch1.js b/test/fetch1.js
index 48dc896..6392d7e 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -27,7 +27,7 @@ const fetch =
~((fetch) => {
Promise.allSettled(
- urls.map((url) => {
+ urls.map(async (url) => {
return fetch(url, { timeout: 2000, redirect: "manual" }).then(
(r) => {
return formatresponse(r);
diff --git a/test/fetch2.js b/test/fetch2.js
index ae617dc..c6465a9 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -12,7 +12,7 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
~((fetch) => {
Promise.allSettled(
- urls.map((url) => {
+ urls.map(async (url) => {
return fetch(url, { timeout: 2000, redirect: "manual" }).then(
(r) => {
return formatresponse(r);
From 7eab56789c4d4518865df1e2dbde52166ac9d22b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:44:13 +0800
Subject: [PATCH 102/125] =?UTF-8?q?=E6=95=B4=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/fetch1.js | 2 +-
test/fetch2.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/fetch1.js b/test/fetch1.js
index 6392d7e..e8ec64e 100644
--- a/test/fetch1.js
+++ b/test/fetch1.js
@@ -29,7 +29,7 @@ const fetch =
Promise.allSettled(
urls.map(async (url) => {
return fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
+ async (r) => {
return formatresponse(r);
}
);
diff --git a/test/fetch2.js b/test/fetch2.js
index c6465a9..494191f 100644
--- a/test/fetch2.js
+++ b/test/fetch2.js
@@ -14,7 +14,7 @@ const fetch = fetch2.context({ session: { ca: cert } }).fetch;
Promise.allSettled(
urls.map(async (url) => {
return fetch(url, { timeout: 2000, redirect: "manual" }).then(
- (r) => {
+ async (r) => {
return formatresponse(r);
}
);
From 55e2789f1f4fd1e93e32397971569a30caade24e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 21:54:25 +0800
Subject: [PATCH 103/125] Update redirect.js
---
test/redirect.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/redirect.js b/test/redirect.js
index ec79ed6..fff8923 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -21,6 +21,7 @@ const server = createServer(
const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
res.writeHead(302, { Location: tourl.href });
+ res.write("302");
return res.end();
}
}
From b47ffbaa0cf01896b46a72fd39ed5b0c64401aa9 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 22:16:08 +0800
Subject: [PATCH 104/125] =?UTF-8?q?=E6=95=B4=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 28 +---------------------------
test/simple.js | 12 +++++++-----
test/websocket.js | 1 +
3 files changed, 9 insertions(+), 32 deletions(-)
diff --git a/README.md b/README.md
index c9e362f..61aaf85 100644
--- a/README.md
+++ b/README.md
@@ -61,33 +61,7 @@ server.listen(port, "localhost", function () {
- redirect all http connections to https:
-```javascript
-const httpolyglot = require("@masx200/http-https-spdy-http2-polyglot");
-const fs = require("fs");
-const port = 9000;
-const server = httpolyglot.createServer(
- {
- key: fs.readFileSync("server.key.pem"),
- cert: fs.readFileSync("server.crt.pem"),
- },
- function (req, res) {
- if (!("encrypted" in req.socket)) {
- const host = req.headers["host"];
- const originurl = req.url || "";
- const tourl = new URL(originurl, "https://" + host);
- tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href });
- return res.end();
- } else {
- res.writeHead(200, { "Content-Type": "text/plain" });
- res.end("Welcome, HTTPS user!");
- }
- }
-);
-server.listen(port, "localhost", function () {
- console.log("httpolyglot server listening on port " + port);
-});
-```
+https://github.com/masx200/http-https-spdy-http2-polyglot/blob/master/test/redirect.js
- create a "404 not found" server
diff --git a/test/simple.js b/test/simple.js
index fab2066..4cf1124 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -14,12 +14,14 @@ const server = createServer(
},
async function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
- res.write(
- ("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!\n"
- );
- res.write("alpnProtocol:" + req.socket.alpnProtocol + " \n");
+ const body =
+ ("encrypted" in req.socket ? "HTTPS" : "HTTP") +
+ " Connection!\n" +
+ "alpnProtocol:" +
+ req.socket.alpnProtocol +
+ " \n";
- res.end();
+ res.end(body);
}
);
diff --git a/test/websocket.js b/test/websocket.js
index 22d5dce..3da589f 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -37,6 +37,7 @@ const server = createServer(
res.end();
} else {
res.statusCode = 404;
+ res.write("404");
res.end();
}
},
From 0e4a9cfea05d23fa8982abdb23df37ab81dfccec Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 22:22:35 +0800
Subject: [PATCH 105/125] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/declaration.js | 1 +
lib/declaration.ts | 1 +
test/redirect.js | 2 +-
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/declaration.js b/lib/declaration.js
index ff49eb9..5d8511a 100644
--- a/lib/declaration.js
+++ b/lib/declaration.js
@@ -1,5 +1,6 @@
export const requestNotFound = function (req, res) {
res.statusCode = 404;
+ res.setHeader("content-type", "text/html");
res.write("404");
res.end();
};
diff --git a/lib/declaration.ts b/lib/declaration.ts
index a3c0863..2442f98 100644
--- a/lib/declaration.ts
+++ b/lib/declaration.ts
@@ -35,6 +35,7 @@ export const requestNotFound = function (
res: ServerResponse
) {
res.statusCode = 404;
+ res.setHeader("content-type", "text/html");
res.write("404");
res.end();
};
diff --git a/test/redirect.js b/test/redirect.js
index fff8923..05e8c97 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -13,7 +13,7 @@ const server = createServer(
},
function (req, res) {
if ("encrypted" in req.socket) {
- res.writeHead(200, { "Content-Type": "text/plain" });
+ res.writeHead(200, { "Content-Type": "text/html" });
res.end("Welcome, HTTPS user!");
} else {
const host = req.headers["host"];
From 9a882e53b7c4b68296d3fbbdd8b15d3289889920 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 22:25:53 +0800
Subject: [PATCH 106/125] Update redirect.js
---
test/redirect.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/redirect.js b/test/redirect.js
index 05e8c97..1a7fd10 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -20,7 +20,7 @@ const server = createServer(
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href });
+ res.writeHead(302, { Location: tourl.href,"Content-Type": "text/html" });
res.write("302");
return res.end();
}
From 0c7ce1b1b56ba5c8d36c04c53fb920a0a46058c9 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Mon, 20 Apr 2020 22:29:33 +0800
Subject: [PATCH 107/125] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 61aaf85..08d29ea 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@ const server = httpolyglot.createServer(
cert: fs.readFileSync("server.crt.pem"),
},
function (req, res) {
- res.writeHead(200, { "Content-Type": "text/plain" });
+ res.writeHead(200, { "Content-Type": "text/html" });
res.end(
("encrypted" in req.socket ? "HTTPS" : "HTTP") + " Connection!"
);
From 77265ca845e37b0553fb8c87154806e6d4628608 Mon Sep 17 00:00:00 2001
From: masx200
Date: Tue, 21 Apr 2020 00:17:18 +0800
Subject: [PATCH 108/125] Update index.ts
---
lib/index.ts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/index.ts b/lib/index.ts
index 6a5cdc9..fd4afc2 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -18,6 +18,8 @@ function createServer(
if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
+ requestListener = requestListener || requestNotFound;
+ upgradeListener = upgradeListener || upgradeNotFound;
const servernet = net.createServer(config);
const serverhttp = http.createServer(config);
From 5008bdd925596804b23c7c3b2347619de568520e Mon Sep 17 00:00:00 2001
From: masx200
Date: Tue, 21 Apr 2020 00:19:18 +0800
Subject: [PATCH 109/125] update .gitignore
---
.gitignore | 1 +
lib/index.js | 2 ++
package.json | 2 +-
server.crt.pem | 22 ----------------------
server.key.pem | 28 ----------------------------
test/redirect.js | 5 ++++-
6 files changed, 8 insertions(+), 52 deletions(-)
delete mode 100644 server.crt.pem
delete mode 100644 server.key.pem
diff --git a/.gitignore b/.gitignore
index 3c3629e..f5164ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
node_modules
+*.pem
\ No newline at end of file
diff --git a/lib/index.js b/lib/index.js
index 93fc140..4d295f5 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -12,6 +12,8 @@ function createServer(
if (!(config && typeof config === "object")) {
throw new Error("options are required!");
}
+ requestListener = requestListener || requestNotFound;
+ upgradeListener = upgradeListener || upgradeNotFound;
const servernet = net.createServer(config);
const serverhttp = http.createServer(config);
const serverspdy = spdy.createServer(config);
diff --git a/package.json b/package.json
index bfb2794..d8cf432 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"type": "module",
"types": "./lib/index.d.ts",
"name": "@masx200/http-https-spdy-http2-polyglot",
- "version": "1.0.0",
+ "version": "1.0.1",
"main": "./lib/index.js",
"scripts": {
"fetch1": "node --experimental-modules ./test/fetch1.js ",
diff --git a/server.crt.pem b/server.crt.pem
deleted file mode 100644
index a6c8f1c..0000000
--- a/server.crt.pem
+++ /dev/null
@@ -1,22 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDszCCApugAwIBAgIUR48GNH+FtTTJpeoE06dMGncARAcwDQYJKoZIhvcNAQEL
-BQAwaTELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREwDwYDVQQHDAhT
-aGFuZ2hhaTEPMA0GA1UECgwGYm95dXNjMQ8wDQYDVQQLDAZib3l1c2MxEjAQBgNV
-BAMMCWxvY2FsaG9zdDAeFw0yMDA0MjAxMzAwNDJaFw0yMTA0MjAxMzAwNDJaMGkx
-CzAJBgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZ2hhaTERMA8GA1UEBwwIU2hhbmdo
-YWkxDzANBgNVBAoMBmJveXVzYzEPMA0GA1UECwwGYm95dXNjMRIwEAYDVQQDDAls
-b2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpuS0fAr08
-OrjWYFKzkemcWgHVd8nsyYPUORm4Ctw/Np93YJzzSe38Gy6G6frD5iQIGzbWaMm8
-tDEHpf2eNxAO2F2ASx3wg2IkHxDQ2dbaxLL/NupgpQDcbZgJEzgHXK1kX7Pa5Jkp
-czh9u5Av9phACulYaIgIvIUHB70eJ2nHjqplAWDCv1utcgKCeBPZS/hk+E5wckv/
-wFomBu+P0R/vTNOH9plXQSZulorjxGkTYD4X1oeyaA3V8UOTie+aEnoXdwI+pTSq
-M6mGM8CKpOngxrHzmPNv3P70ncn04BN81ljYJ3z8ot6NxM9+1wcf5CXqo066UmgD
-GGY1GH85VQrLAgMBAAGjUzBRMB0GA1UdDgQWBBSacHb7ensjgNErYHmJNoZW4kbq
-WjAfBgNVHSMEGDAWgBSacHb7ensjgNErYHmJNoZW4kbqWjAPBgNVHRMBAf8EBTAD
-AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAg+Pr2lKVdGlCqSVW62wh6X+YpkWN7rIbG
-lDRuBL6vrGZYFaJrWAGfjD3x3pgYf7S3APxOPjs3ihO5Pxh2btk856GP7RIed7Ho
-Q31VSzLUl75u6ytCJF6pFZKaGP+T8WqF3rpEqo5fJebzEFCgloKpJxuwPN+tcEhQ
-WcdaDJuaspOTTKr0buARZybj86cCdH/R9zr0n9sDzqWIBnJ1dd22BV0UwVSamdTe
-b2ENZYAKbX5Yto9KCFwLWphYK8IS1zQX0QdFYoVDlyroI99fgQdGOthUXImvZuZv
-CRgSrRakQvAzCBXG1uaPajdRIATJDGlQmx4/e4Do9sG3V1BTt67P
------END CERTIFICATE-----
diff --git a/server.key.pem b/server.key.pem
deleted file mode 100644
index 389d948..0000000
--- a/server.key.pem
+++ /dev/null
@@ -1,28 +0,0 @@
------BEGIN PRIVATE KEY-----
-MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCpuS0fAr08OrjW
-YFKzkemcWgHVd8nsyYPUORm4Ctw/Np93YJzzSe38Gy6G6frD5iQIGzbWaMm8tDEH
-pf2eNxAO2F2ASx3wg2IkHxDQ2dbaxLL/NupgpQDcbZgJEzgHXK1kX7Pa5Jkpczh9
-u5Av9phACulYaIgIvIUHB70eJ2nHjqplAWDCv1utcgKCeBPZS/hk+E5wckv/wFom
-Bu+P0R/vTNOH9plXQSZulorjxGkTYD4X1oeyaA3V8UOTie+aEnoXdwI+pTSqM6mG
-M8CKpOngxrHzmPNv3P70ncn04BN81ljYJ3z8ot6NxM9+1wcf5CXqo066UmgDGGY1
-GH85VQrLAgMBAAECggEALnkG8tvUJx7JJ+IeIw9MEUTQBbyULOMM1tp/wVYv8psp
-VQ2+TButL3/d4JFG2cc1jIavIEx3GNWaK0b3SBA5tGboS03GN+oxwERFXXqYizSa
-8qj9ylLEBpd3rtx1Vga5b6eI3uIDUkc7a6olFA0IqViThmKxBPthzYf/77bJDxv+
-P9goEfsOJCNjogDCrM5g9inDfQ1L6yxFngmn/R4R6RrdBUk9pmOK+i8hrrVsAVzr
-9qfMumwf2y6Hc/t+b+7cvG9yIYH26oZuMnqsAZnGRfzVXkOTFEbq8yo8UqTIRoB9
-D0p8GoLFQXNgBwRYtLvQ+6F62cHjmJZWxlqawNMEgQKBgQDTrPYGViNaSyPdf4JQ
-y8IZpsLCZV3NBzk+Wk6KUEnN0BTnulK63oA176xOG+3MeUlItpJylLcKSzHUcc/k
-6eihFDIiPco8MCLROcEMvqXwGy1mM+BTdJQAYTWzT5NutNhzn5emBFwONF99OWLu
-1TqnFy6v+nrPAImIv5jfOBZTCwKBgQDNQ1R3e1R16y2bhr3xw+0bPJC9NLX09ObK
-2N6Vrw7RK7fw0p16lndzdbZE23sZwkqyKlw2+teZUHsQMyG75Ffx/OsMpEh7s3dr
-iZCNwqQIbR7nh7qLwTkroEWO6IEOs2jaOaNoI4hIcy3rn4lpdoWinM+WGdWqsVul
-SNr7VBb/QQKBgGcUxJ6jVgYDr4yPKrwD7hslzZRzXrGYwfSub68FmFtk6LlMUDt2
-XUNm2ycSjMRVkC2b00d/Sn/1zGdjoVUd386JkjyAkLqsylfPY0a8lPyPj5VE0Ap0
-LBrfPBJ9PxPbd8kev+/2EYpNUO8fgiFCr5RtQqwqM6IY5eE1RNH3c0+vAoGBAIgv
-tekYQK+D+9yGh5vSnIxHoNiIEnmVy1KmlPfHEBOj6AS2GJnvHw3R+b6xyHkMubZ/
-+HLZ9xXXme7jnewl0lvRrLnUferk5cTJnskPbPnSPIDtQs3aw224hq4MgSQZ0OWI
-/Gvpt1Aqazs7vFXmtz9uvyQdu+/mgKGnNvMtlZyBAoGBAMIx5crrxOwyGSohdDJr
-iQCmt3SVStmE82XDh8LpK13+iQyPjJ9emDBg5G6iyyf7xMoZxcFW7p3faH/davPF
-aP2HXSP1HAS3Bf7y7+rBF7uSvGgBZiQLb7N4a5k9geDSkNDi0z0nHUO6m5JC36/J
-8tuDzk8Zr5U9TBgx4NjV4hib
------END PRIVATE KEY-----
diff --git a/test/redirect.js b/test/redirect.js
index 1a7fd10..44b5604 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -20,7 +20,10 @@ const server = createServer(
const originurl = req.url || "";
const tourl = new URL(originurl, "https://" + host);
tourl.port = String(port);
- res.writeHead(302, { Location: tourl.href,"Content-Type": "text/html" });
+ res.writeHead(302, {
+ Location: tourl.href,
+ "Content-Type": "text/html",
+ });
res.write("302");
return res.end();
}
From 3545b4ab848bac8d564649670ba20eee0966afea Mon Sep 17 00:00:00 2001
From: masx200
Date: Tue, 21 Apr 2020 00:23:19 +0800
Subject: [PATCH 110/125] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E6=95=B4=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/README.md b/README.md
index 08d29ea..93b7bb9 100644
--- a/README.md
+++ b/README.md
@@ -98,3 +98,29 @@ TLS and HTTP connections are easy to distinguish based on the first byte sent by
https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155
https://github.com/httptoolkit/httpolyglot/blob/master/lib/index.js
+
+# test
+
+```powershell
+yarn install
+```
+
+```powershell
+./generate-ssl-cert.ps1
+```
+
+```powershell
+yarn serve
+```
+
+```powershell
+yarn fetch1
+```
+
+```powershell
+yarn fetch2
+```
+
+```powershell
+yarn open
+```
From d098b5c960f3b7f54326d57ed3806b0d671ea038 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 00:33:05 +0800
Subject: [PATCH 111/125] Update README.md
---
README.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/README.md b/README.md
index 93b7bb9..3f541f9 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,11 @@ yarn install
./generate-ssl-cert.ps1
```
+```powershell
+yarn build
+```
+
+
```powershell
yarn serve
```
From a3afb21e84bd0ad04d31e4149aec1d8fa43ada6b Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 07:59:05 +0800
Subject: [PATCH 112/125] Update index.ts
---
lib/index.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/index.ts b/lib/index.ts
index fd4afc2..170c61d 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -57,6 +57,7 @@ function createServer(
// serverspdy.addListener("connection", connectionListener);
servernet.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
+console.assert(Reflect.get(socket,"allowHalfOpen")===false)
/* 类型“Socket”上不存在属性“allowHalfOpen” */
// socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
From 54440c1af37fdcce0309bc13b484fa3c8557491d Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:25:22 +0800
Subject: [PATCH 113/125] =?UTF-8?q?=E7=BE=8E=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 1 -
lib/index.js | 1 +
lib/index.ts | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 3f541f9..259b6cf 100644
--- a/README.md
+++ b/README.md
@@ -113,7 +113,6 @@ yarn install
yarn build
```
-
```powershell
yarn serve
```
diff --git a/lib/index.js b/lib/index.js
index 4d295f5..d6174c4 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -29,6 +29,7 @@ function createServer(
}
servernet.addListener("connection", connectionListener);
function connectionListener(socket) {
+ console.assert(Reflect.get(socket, "allowHalfOpen") === false);
if (!socket.listeners("error").length) {
socket.on("error", function () {});
}
diff --git a/lib/index.ts b/lib/index.ts
index 170c61d..0ee399c 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -57,7 +57,7 @@ function createServer(
// serverspdy.addListener("connection", connectionListener);
servernet.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
-console.assert(Reflect.get(socket,"allowHalfOpen")===false)
+ console.assert(Reflect.get(socket, "allowHalfOpen") === false);
/* 类型“Socket”上不存在属性“allowHalfOpen” */
// socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
From 4be3e5b33ebda3efcea79fb85e9476d0bf6be746 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:44:37 +0800
Subject: [PATCH 114/125] Create early-disconnect.js
---
test/early-disconnect.js | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 test/early-disconnect.js
diff --git a/test/early-disconnect.js b/test/early-disconnect.js
new file mode 100644
index 0000000..5987dc5
--- /dev/null
+++ b/test/early-disconnect.js
@@ -0,0 +1,32 @@
+import assert from "assert";
+import { Socket } from "net";
+import { createServer } from "../lib/index.js";
+import { cert, key } from "./key-cert.js";
+const port = 0;
+// @ts-ignore
+
+const server = createServer(
+ {
+ key,
+ cert,
+ },
+ async function (req, res) {
+ assert(false, "Request handler should not be called");
+ }
+);
+
+server.listen(port, "localhost", function () {
+ var port = this.address().port;
+ console.log("httpolyglot server listening on port " + port);
+ const socket = new Socket();
+
+ socket.connect(port, "localhost", () => {
+ console.log("client connect");
+ server.close(() => {
+ console.log("server close");
+ });
+ socket.on("close", (e) => {
+ console.log("client close", e);
+ });
+ });
+});
From e915253cdaf810055970b6531a811ead81ea254c Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:47:08 +0800
Subject: [PATCH 115/125] Update index.ts
---
lib/index.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/index.ts b/lib/index.ts
index 0ee399c..ae62be7 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,6 +1,7 @@
import http from "http";
import net from "net";
import spdy from "spdy";
+import assert from "assert";
import {
requestNotFound,
upgradeNotFound,
@@ -10,6 +11,7 @@ import {
} from "./declaration.js";
export * from "./declaration.js";
export { createServer };
+
function createServer(
config: ServerOptions,
requestListener: RequestListener = requestNotFound,
@@ -57,7 +59,7 @@ function createServer(
// serverspdy.addListener("connection", connectionListener);
servernet.addListener("connection", connectionListener);
function connectionListener(socket: net.Socket) {
- console.assert(Reflect.get(socket, "allowHalfOpen") === false);
+ assert(Reflect.get(socket, "allowHalfOpen") === false);
/* 类型“Socket”上不存在属性“allowHalfOpen” */
// socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
From d247eb6f5ca4216cee87beed4edf3c1adeea9ace Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:48:14 +0800
Subject: [PATCH 116/125] assert(Reflect.get(socket, "allowHalfOpen") ===
false);
---
lib/index.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/index.js b/lib/index.js
index d6174c4..817d578 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,6 +1,7 @@
import http from "http";
import net from "net";
import spdy from "spdy";
+import assert from "assert";
import { requestNotFound, upgradeNotFound } from "./declaration.js";
export * from "./declaration.js";
export { createServer };
@@ -29,7 +30,7 @@ function createServer(
}
servernet.addListener("connection", connectionListener);
function connectionListener(socket) {
- console.assert(Reflect.get(socket, "allowHalfOpen") === false);
+ assert(Reflect.get(socket, "allowHalfOpen") === false);
if (!socket.listeners("error").length) {
socket.on("error", function () {});
}
From 0d60ca53ce676bbda6514eeeca8f32bdad3f07b2 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:49:05 +0800
Subject: [PATCH 117/125] Update package.json
---
package.json | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index d8cf432..b71ac1b 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"type": "module",
"types": "./lib/index.d.ts",
"name": "@masx200/http-https-spdy-http2-polyglot",
- "version": "1.0.1",
+ "version": "1.0.2",
"main": "./lib/index.js",
"scripts": {
"fetch1": "node --experimental-modules ./test/fetch1.js ",
@@ -22,7 +22,8 @@
"http",
"https",
"multiplex",
- "polyglot"
+ "polyglot",
+ "http2"
],
"dependencies": {
"@types/node": "^13.13.0",
From 4a4362e1e77f0abfa0e42309f86a1e24af5c1ad0 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:49:36 +0800
Subject: [PATCH 118/125] Update README.md
---
README.md | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 259b6cf..7c3f237 100644
--- a/README.md
+++ b/README.md
@@ -118,11 +118,7 @@ yarn serve
```
```powershell
-yarn fetch1
-```
-
-```powershell
-yarn fetch2
+yarn test
```
```powershell
From bddefe99636a4387f1266638c871f281f9d1cba3 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:52:44 +0800
Subject: [PATCH 119/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/notfound.js | 5 +----
test/push.js | 5 +----
test/redirect.js | 5 +----
test/simple.js | 5 -----
test/websocket.js | 7 +++----
5 files changed, 6 insertions(+), 21 deletions(-)
diff --git a/test/notfound.js b/test/notfound.js
index 4be8f96..c2ead69 100644
--- a/test/notfound.js
+++ b/test/notfound.js
@@ -1,11 +1,8 @@
-import { dirname } from "path";
-import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
const port = 8998;
// @ts-ignore
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
+
const server = createServer({
key,
cert,
diff --git a/test/push.js b/test/push.js
index 968622d..8ca3d6d 100644
--- a/test/push.js
+++ b/test/push.js
@@ -1,11 +1,8 @@
-import { dirname } from "path";
-import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
const port = 9002;
// @ts-ignore
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
+
const server = createServer(
{
key,
diff --git a/test/redirect.js b/test/redirect.js
index 44b5604..e022508 100644
--- a/test/redirect.js
+++ b/test/redirect.js
@@ -1,10 +1,7 @@
-import { dirname } from "path";
-import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
// @ts-ignore
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
+
const port = 9001;
const server = createServer(
{
diff --git a/test/simple.js b/test/simple.js
index 4cf1124..6b49f9f 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -1,12 +1,7 @@
-import { dirname } from "path";
-import { fileURLToPath } from "url";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
const port = 9000;
-// @ts-ignore
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
const server = createServer(
{
key,
diff --git a/test/websocket.js b/test/websocket.js
index 3da589f..e739d42 100644
--- a/test/websocket.js
+++ b/test/websocket.js
@@ -1,11 +1,10 @@
-import { createServer } from "../lib/index.js";
import fs from "fs";
-const port = 8999;
-import path from "path";
+import path, { dirname } from "path";
import { fileURLToPath } from "url";
-import { dirname } from "path";
import ws from "ws";
+import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
+const port = 8999;
const wsServer = new ws.Server({ noServer: true });
wsServer.on("connection", (websocket, req) => {
websocket.send(JSON.stringify(req.headers));
From c26390cc7424ab18180c5e0d13e402bf826ff7c8 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 09:57:29 +0800
Subject: [PATCH 120/125] Update index.js
---
test/index.js | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/test/index.js b/test/index.js
index f2f1b57..02d608b 100644
--- a/test/index.js
+++ b/test/index.js
@@ -6,8 +6,18 @@ if (url.protocol === "https:") {
}
let socket = new WebSocket(url.href);
-
+/**
+ * @param {string} message
+ */
+function appendtodom(message) {
+ let p = document.createElement("p");
+ p.innerText = message;
+ document.body.appendChild(p);
+}
socket.addEventListener("close", console.log);
socket.addEventListener("open", console.log);
socket.addEventListener("error", console.log);
socket.addEventListener("message", console.log);
+socket.addEventListener("message", (e) => {
+ appendtodom(e.data);
+});
From 75f8cc052e34589e7e84b5914a3a249a1b880847 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 10:05:44 +0800
Subject: [PATCH 121/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 3 +--
test/test.js | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
create mode 100644 test/test.js
diff --git a/package.json b/package.json
index b71ac1b..379f5af 100644
--- a/package.json
+++ b/package.json
@@ -5,8 +5,7 @@
"version": "1.0.2",
"main": "./lib/index.js",
"scripts": {
- "fetch1": "node --experimental-modules ./test/fetch1.js ",
- "fetch2": " node --experimental-modules ./test/fetch2.js",
+ "test": "node --experimental-modules ./test/test.js ",
"open": "node --experimental-modules ./test/open.js",
"build": "tsc",
"serve": "node --experimental-modules ./test/serve.js",
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..a82bda6
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,22 @@
+import { execFile } from "child_process";
+// @ts-ignore
+import path, { dirname } from "path";
+import { fileURLToPath } from "url";
+import util from "util";
+process.on("unhandledRejection", console.error);
+// @ts-ignore
+const execpro = util.promisify(execFile);
+// @ts-ignore
+const __filename = fileURLToPath(import.meta.url);
+var __dirname = dirname(__filename);
+const files = ["early-disconnect.js", "fetch1.js", "fetch2.js"].map((p) =>
+ path.join(__dirname, p)
+);
+files.reduce(async (prev, file) => {
+ await prev;
+ const result = await execpro("node", [file]);
+ const { stdout, stderr } = result;
+ console.log(file);
+ console.log(stdout);
+ console.log(stderr);
+}, Promise.resolve());
From 1c01d713f9464887b88fea99a10253917a20bd5e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 10:11:54 +0800
Subject: [PATCH 122/125] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/early-client-disconnect.js | 34 +++++++++++++++++++
...sconnect.js => early-server-disconnect.js} | 0
test/test.js | 9 +++--
3 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 test/early-client-disconnect.js
rename test/{early-disconnect.js => early-server-disconnect.js} (100%)
diff --git a/test/early-client-disconnect.js b/test/early-client-disconnect.js
new file mode 100644
index 0000000..a2e4eb4
--- /dev/null
+++ b/test/early-client-disconnect.js
@@ -0,0 +1,34 @@
+import assert from "assert";
+import { Socket } from "net";
+import { createServer } from "../lib/index.js";
+import { cert, key } from "./key-cert.js";
+const port = 0;
+// @ts-ignore
+
+const server = createServer(
+ {
+ key,
+ cert,
+ },
+ async function (req, res) {
+ assert(false, "Request handler should not be called");
+ }
+);
+
+server.listen(port, "localhost", function () {
+ var port = this.address().port;
+ console.log("httpolyglot server listening on port " + port);
+ const socket = new Socket();
+
+ socket.connect(port, "localhost", () => {
+ console.log("client connect");
+ socket.end(() => {
+ server.close(() => {
+ console.log("server close");
+ });
+ });
+ socket.on("close", (e) => {
+ console.log("client close", e);
+ });
+ });
+});
diff --git a/test/early-disconnect.js b/test/early-server-disconnect.js
similarity index 100%
rename from test/early-disconnect.js
rename to test/early-server-disconnect.js
diff --git a/test/test.js b/test/test.js
index a82bda6..b30f448 100644
--- a/test/test.js
+++ b/test/test.js
@@ -9,9 +9,12 @@ const execpro = util.promisify(execFile);
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
var __dirname = dirname(__filename);
-const files = ["early-disconnect.js", "fetch1.js", "fetch2.js"].map((p) =>
- path.join(__dirname, p)
-);
+const files = [
+ "early-server-disconnect.js",
+ "early-client-disconnect.js",
+ "fetch1.js",
+ "fetch2.js",
+].map((p) => path.join(__dirname, p));
files.reduce(async (prev, file) => {
await prev;
const result = await execpro("node", [file]);
From 6ab839a397bfbe6c0b8de12e2ca1b1caeb5c5529 Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 13:44:32 +0800
Subject: [PATCH 123/125] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/index.js | 18 +++++++++--
lib/index.ts | 57 ++++++++++++++++-----------------
package.json | 2 +-
test/early-client-disconnect.js | 24 +++++++-------
test/early-server-disconnect.js | 12 +++----
test/test.js | 1 +
test/tls-early-disconnect.js | 57 +++++++++++++++++++++++++++++++++
7 files changed, 121 insertions(+), 50 deletions(-)
create mode 100644 test/tls-early-disconnect.js
diff --git a/lib/index.js b/lib/index.js
index 817d578..4d2ee00 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,7 +1,7 @@
+import assert from "assert";
import http from "http";
import net from "net";
import spdy from "spdy";
-import assert from "assert";
import { requestNotFound, upgradeNotFound } from "./declaration.js";
export * from "./declaration.js";
export { createServer };
@@ -18,6 +18,20 @@ function createServer(
const servernet = net.createServer(config);
const serverhttp = http.createServer(config);
const serverspdy = spdy.createServer(config);
+ servernet.addListener("error", () => {});
+ serverhttp.addListener("ClientError", (err, socket) => {
+ socket.destroy();
+ });
+ serverhttp.addListener("error", () => {});
+ serverspdy.addListener("tlsClientError", (err, socket) => {
+ socket.destroy();
+ });
+ serverspdy.addListener("error", () => {});
+ serverspdy.prependListener("secureConnection", (socket) => {
+ if (!socket.listeners("error").length) {
+ socket.on("error", () => {});
+ }
+ });
serverhttp.addListener("upgrade", upgradeListener);
serverspdy.addListener("upgrade", upgradeListener);
serverhttp.addListener("request", requestListener);
@@ -32,7 +46,7 @@ function createServer(
function connectionListener(socket) {
assert(Reflect.get(socket, "allowHalfOpen") === false);
if (!socket.listeners("error").length) {
- socket.on("error", function () {});
+ socket.on("error", () => {});
}
const data = socket.read(1);
if (data === null) {
diff --git a/lib/index.ts b/lib/index.ts
index ae62be7..7ccd163 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,13 +1,14 @@
+import assert from "assert";
import http from "http";
import net from "net";
import spdy from "spdy";
-import assert from "assert";
+import tls from "tls";
import {
- requestNotFound,
- upgradeNotFound,
RequestListener,
+ requestNotFound,
ServerOptions,
UpgradeListener,
+ upgradeNotFound,
} from "./declaration.js";
export * from "./declaration.js";
export { createServer };
@@ -27,31 +28,35 @@ function createServer(
const serverhttp = http.createServer(config);
//@ts-ignore
const serverspdy = spdy.createServer(config);
+ servernet.addListener("error", () => {});
+ serverhttp.addListener("ClientError", (err: Error, socket: net.Socket) => {
+ socket.destroy();
+ });
+ serverhttp.addListener("error", () => {});
+ serverspdy.addListener(
+ "tlsClientError",
+ (err: Error, socket: tls.TLSSocket) => {
+ socket.destroy();
+ }
+ );
+ serverspdy.addListener("error", () => {});
+ serverspdy.prependListener("secureConnection", (socket: tls.TLSSocket) => {
+ if (!socket.listeners("error").length) {
+ socket.on("error", () => {});
+ }
+ });
serverhttp.addListener("upgrade", upgradeListener);
serverspdy.addListener("upgrade", upgradeListener);
serverhttp.addListener("request", requestListener);
serverspdy.addListener("request", requestListener);
- // serverhttp.addListener(
- // "upgrade",
- // (request: ServerRequest, socket: Socket, head: Buffer) => {
- // serverspdy.emit("upgrade", request, socket, head);
- // }
- // );
- // serverhttp.removeAllListeners("request");
- // serverspdy.removeAllListeners("request");
- // serverspdy.addListener("request", requestListener);
- // serverhttp.addListener("request", (req, res) => {
- // serverspdy.emit("request", req, res);
- // });
-
- // serverspdy.addListener("upgrade", upgradeListener);
- // const onconnection = serverspdy.listeners("connection");
- // serverspdy.removeAllListeners("connection");
+ /* 修复bug
+ 程序没有监听套接字上的error事件,然后程序崩溃了
+net.Socket
+tls.TLSSocket
+自动监听error事件,防止服务器意外退出
+*/
function handletls(socket: net.Socket) {
serverspdy.emit("connection", socket);
- // onconnection.forEach((listeners: Function) =>
- // Reflect.apply(listeners, serverspdy, [socket])
- // );
}
function handlehttp(socket: net.Socket) {
serverhttp.emit("connection", socket);
@@ -64,7 +69,7 @@ function createServer(
// socket.allowHalfOpen = false;
//如果没有error监听器就添加error 监听器
if (!socket.listeners("error").length) {
- socket.on("error", function () {});
+ socket.on("error", () => {});
}
// let ishttp = false;
// let istls = false;
@@ -91,12 +96,6 @@ function createServer(
} else {
socket.destroy();
}
- // if (ishttp) {
-
- // }
- // if (istls) {
-
- // }
}
/* 测试发现不能使用on data事件,会收不到响应,多次数据会漏掉 */
}
diff --git a/package.json b/package.json
index 379f5af..c3276ab 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"type": "module",
"types": "./lib/index.d.ts",
"name": "@masx200/http-https-spdy-http2-polyglot",
- "version": "1.0.2",
+ "version": "1.0.3",
"main": "./lib/index.js",
"scripts": {
"test": "node --experimental-modules ./test/test.js ",
diff --git a/test/early-client-disconnect.js b/test/early-client-disconnect.js
index a2e4eb4..73eae81 100644
--- a/test/early-client-disconnect.js
+++ b/test/early-client-disconnect.js
@@ -1,5 +1,5 @@
import assert from "assert";
-import { Socket } from "net";
+import net from "net";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
const port = 0;
@@ -18,17 +18,19 @@ const server = createServer(
server.listen(port, "localhost", function () {
var port = this.address().port;
console.log("httpolyglot server listening on port " + port);
- const socket = new Socket();
-
- socket.connect(port, "localhost", () => {
+ const socket = net.connect(port, "localhost", () => {
console.log("client connect");
- socket.end(() => {
- server.close(() => {
- console.log("server close");
- });
- });
- socket.on("close", (e) => {
- console.log("client close", e);
+ });
+ socket.on("error", console.error);
+ socket.write(Buffer.from([0]));
+
+ socket.end(() => {
+ console.log("client end");
+ });
+ socket.on("close", (e) => {
+ console.log("client close", e);
+ server.close(() => {
+ console.log("server close");
});
});
});
diff --git a/test/early-server-disconnect.js b/test/early-server-disconnect.js
index 5987dc5..74752c0 100644
--- a/test/early-server-disconnect.js
+++ b/test/early-server-disconnect.js
@@ -1,5 +1,5 @@
import assert from "assert";
-import { Socket } from "net";
+import net from "net";
import { createServer } from "../lib/index.js";
import { cert, key } from "./key-cert.js";
const port = 0;
@@ -18,15 +18,13 @@ const server = createServer(
server.listen(port, "localhost", function () {
var port = this.address().port;
console.log("httpolyglot server listening on port " + port);
- const socket = new Socket();
-
- socket.connect(port, "localhost", () => {
+ const socket = net.connect(port, "localhost", () => {
console.log("client connect");
server.close(() => {
console.log("server close");
});
- socket.on("close", (e) => {
- console.log("client close", e);
- });
+ });
+ socket.on("close", (e) => {
+ console.log("client close", e);
});
});
diff --git a/test/test.js b/test/test.js
index b30f448..7341eee 100644
--- a/test/test.js
+++ b/test/test.js
@@ -10,6 +10,7 @@ const execpro = util.promisify(execFile);
const __filename = fileURLToPath(import.meta.url);
var __dirname = dirname(__filename);
const files = [
+ "tls-early-disconnect.js",
"early-server-disconnect.js",
"early-client-disconnect.js",
"fetch1.js",
diff --git a/test/tls-early-disconnect.js b/test/tls-early-disconnect.js
new file mode 100644
index 0000000..5aa5be5
--- /dev/null
+++ b/test/tls-early-disconnect.js
@@ -0,0 +1,57 @@
+import assert from "assert";
+import tls from "tls";
+import { createServer } from "../lib/index.js";
+import { cert, key } from "./key-cert.js";
+
+const port = 0;
+// @ts-ignore
+
+const server = createServer(
+ {
+ key,
+ cert,
+ },
+ async function (req, res) {
+ assert(false, "Request handler should not be called");
+ }
+);
+const host = "localhost";
+server.listen(port, host, function () {
+ var port = this.address().port;
+ console.log("httpolyglot server listening on port " + port);
+
+ const socket = tls.connect({
+ port: port,
+ host: host,
+ ca: cert,
+ timeout: 2000,
+ });
+ socket.on("session", (session) => {
+ console.log("client session", session);
+ });
+ socket.on("secureConnect", () => {
+ console.log("client connect");
+ socket.end();
+ socket.destroy();
+ });
+ socket.on("close", (e) => {
+ console.log("client close", e);
+ server.close((e) => {
+ console.log("server close", e);
+ });
+ });
+ // socket.on("error", console.error);
+ // socket.connect(port, "localhost", () => {
+ // console.log("client connect");
+ // socket.end(() => {
+ // console.log("client end");
+ // });
+ // socket.destroy();
+ // socket.on("close", (e) => {
+ // console.log("client close", e);
+ // server.close(() => {
+ // console.log("server close");
+ // });
+ // });
+ // });
+});
From 4f4d25a5392457d76dacfca472f4508b0f3c1b8f Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 14:54:00 +0800
Subject: [PATCH 124/125] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=20"@microso?=
=?UTF-8?q?ft/api-extractor"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
api-extractor.json | 21 +++++
dist/index.d.ts | 62 ++++++++++++++
lib/declaration.d.ts | 4 +-
lib/declaration.d.ts.map | 1 +
lib/declaration.ts | 2 +-
lib/index.d.ts | 1 +
lib/index.d.ts.map | 1 +
package.json | 9 +-
tsconfig.json | 2 +
yarn.lock | 176 +++++++++++++++++++++++++++++++++++++++
10 files changed, 272 insertions(+), 7 deletions(-)
create mode 100644 api-extractor.json
create mode 100644 dist/index.d.ts
create mode 100644 lib/declaration.d.ts.map
create mode 100644 lib/index.d.ts.map
diff --git a/api-extractor.json b/api-extractor.json
new file mode 100644
index 0000000..ce00a70
--- /dev/null
+++ b/api-extractor.json
@@ -0,0 +1,21 @@
+{
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
+ "mainEntryPointFilePath": "/lib/index.d.ts",
+ "bundledPackages": [],
+ "compiler": {},
+ "apiReport": { "enabled": false },
+ "docModel": { "enabled": false },
+ "dtsRollup": {
+ "enabled": true,
+ "untrimmedFilePath": "/dist/index.d.ts"
+ },
+ "tsdocMetadata": { "enabled": false },
+ "messages": {
+ "compilerMessageReporting": { "default": { "logLevel": "warning" } },
+ "extractorMessageReporting": {
+ "ae-missing-release-tag": { "logLevel": "none" },
+ "default": { "logLevel": "warning" }
+ },
+ "tsdocMessageReporting": { "default": { "logLevel": "warning" } }
+ }
+}
diff --git a/dist/index.d.ts b/dist/index.d.ts
new file mode 100644
index 0000000..74d6844
--- /dev/null
+++ b/dist/index.d.ts
@@ -0,0 +1,62 @@
+///
+import http from "http";
+import https from "https";
+import net from "net";
+import spdy from "spdy";
+import stream from "stream";
+import tls from "tls";
+
+export declare function createServer(
+ config: ServerOptions,
+ requestListener?: RequestListener,
+ upgradeListener?: UpgradeListener
+): net.Server;
+
+export declare interface PushOptions {
+ status?: number;
+ method?: string;
+ request?: http.OutgoingHttpHeaders;
+ response?: http.OutgoingHttpHeaders;
+}
+
+export declare type RequestListener = (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+
+export declare const requestNotFound: (
+ req: ServerRequest,
+ res: ServerResponse
+) => void;
+
+export declare type ServerOptions = spdy.ServerOptions & {
+ allowHalfOpen?: boolean | undefined;
+ pauseOnConnect?: boolean | undefined;
+} & http.ServerOptions &
+ tls.TlsOptions &
+ https.ServerOptions;
+
+export declare interface ServerRequest extends http.IncomingMessage {
+ socket: Socket;
+}
+
+export declare interface ServerResponse extends http.ServerResponse {
+ socket: Socket;
+ push?: (pathname: string, options?: PushOptions) => stream.Writable;
+}
+
+export declare type Socket = Partial & net.Socket;
+
+export declare type UpgradeListener = (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
+
+export declare const upgradeNotFound: (
+ req: ServerRequest,
+ socket: Socket,
+ head: Buffer
+) => void;
+
+export {};
diff --git a/lib/declaration.d.ts b/lib/declaration.d.ts
index 490a601..844cace 100644
--- a/lib/declaration.d.ts
+++ b/lib/declaration.d.ts
@@ -8,7 +8,7 @@ import https from "https";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
-interface PushOptions {
+export interface PushOptions {
status?: number;
method?: string;
request?: http.OutgoingHttpHeaders;
@@ -43,4 +43,4 @@ export declare const upgradeNotFound: (
socket: Socket,
head: Buffer
) => void;
-export {};
+//# sourceMappingURL=declaration.d.ts.map
diff --git a/lib/declaration.d.ts.map b/lib/declaration.d.ts.map
new file mode 100644
index 0000000..ea0d239
--- /dev/null
+++ b/lib/declaration.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["declaration.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,eAAe;IACvD,MAAM,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,WAAW;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;IACnC,QAAQ,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACvC;AACD,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,cAAc;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,QAAQ,CAAC;CACvE;AACD,oBAAY,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;AACzD,oBAAY,eAAe,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;AAChF,oBAAY,eAAe,GAAG,CAC1B,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KACX,IAAI,CAAC;AACV,oBAAY,aAAa,GAAG,IAAI,CAAC,aAAa,GAAG;IAC7C,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC,GAAG,IAAI,CAAC,aAAa,GAClB,GAAG,CAAC,UAAU,GACd,KAAK,CAAC,aAAa,CAAC;AACxB,eAAO,MAAM,eAAe,mDAQ3B,CAAC;AACF,eAAO,MAAM,eAAe,4DAO3B,CAAC"}
\ No newline at end of file
diff --git a/lib/declaration.ts b/lib/declaration.ts
index 2442f98..e84e887 100644
--- a/lib/declaration.ts
+++ b/lib/declaration.ts
@@ -7,7 +7,7 @@ import https from "https";
export interface ServerRequest extends http.IncomingMessage {
socket: Socket;
}
-interface PushOptions {
+export interface PushOptions {
status?: number;
method?: string;
request?: http.OutgoingHttpHeaders;
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 106f240..30de2c4 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -12,3 +12,4 @@ declare function createServer(
requestListener?: RequestListener,
upgradeListener?: UpgradeListener
): net.Server;
+//# sourceMappingURL=index.d.ts.map
diff --git a/lib/index.d.ts.map b/lib/index.d.ts.map
new file mode 100644
index 0000000..2148be6
--- /dev/null
+++ b/lib/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAEA,OAAO,GAAG,MAAM,KAAK,CAAC;AAGtB,OAAO,EACH,eAAe,EAEf,aAAa,EACb,eAAe,EAElB,MAAM,kBAAkB,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,iBAAS,YAAY,CACjB,MAAM,EAAE,aAAa,EACrB,eAAe,GAAE,eAAiC,EAClD,eAAe,GAAE,eAAiC,GACnD,GAAG,CAAC,MAAM,CAoFZ"}
\ No newline at end of file
diff --git a/package.json b/package.json
index c3276ab..d106cd3 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,13 @@
{
"type": "module",
- "types": "./lib/index.d.ts",
+ "types": "./dist/index.d.ts",
"name": "@masx200/http-https-spdy-http2-polyglot",
- "version": "1.0.3",
+ "version": "1.0.4",
"main": "./lib/index.js",
"scripts": {
"test": "node --experimental-modules ./test/test.js ",
"open": "node --experimental-modules ./test/open.js",
- "build": "tsc",
+ "build": "tsc&& api-extractor run --local",
"serve": "node --experimental-modules ./test/serve.js",
"prettier": "prettier --write *.md *.json ./**/*.js */**.ts"
},
@@ -29,9 +29,10 @@
"@types/spdy": "^3.4.4"
},
"devDependencies": {
+ "@microsoft/api-extractor": "^7.7.13",
+ "@types/ws": "^7.2.4",
"fetch-h2": "^2.4.5",
"node-fetch": "^3.0.0-beta.4",
- "@types/ws": "^7.2.4",
"open": "^7.0.3",
"prettier": "^2.0.4",
"spdy": "^4.0.2",
diff --git a/tsconfig.json b/tsconfig.json
index 84796e7..e4eb52f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,4 +1,5 @@
{
+ "$schema": "http://json.schemastore.org/tsconfig",
"include": ["*/**.ts"],
"compilerOptions": {
"baseUrl": ".",
@@ -8,6 +9,7 @@
"moduleResolution": "node",
"resolveJsonModule": false,
"declaration": true,
+ "declarationMap": true,
"allowJs": true,
"checkJs": false,
"charset": "utf-8",
diff --git a/yarn.lock b/yarn.lock
index 842c6db..e8e3b6c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,11 +2,71 @@
# yarn lockfile v1
+"@microsoft/api-extractor-model@7.7.11":
+ version "7.7.11"
+ resolved "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.7.11.tgz#9dfc5425f4a6a2b6b1ebc39332ae8101ab8da36a"
+ integrity sha512-Kf3RytYDq7sP4ASaaA9IcvaOPbVj1Xj34E2Wxd9DznI7sG4HzcpoOGmxaZHCzyYVh7wfAaAlvcXf3SV+djhNZw==
+ dependencies:
+ "@microsoft/tsdoc" "0.12.19"
+ "@rushstack/node-core-library" "3.19.7"
+
+"@microsoft/api-extractor@^7.7.13":
+ version "7.7.13"
+ resolved "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.7.13.tgz#7ee70978825a36d294d26e50b5d888ca3789d1b0"
+ integrity sha512-7+EGunGd7OSfDxZl4aDI4qMWG98+I84vTryNadti+IfgpB9IyhJtgA4r3dCG7hewTwKACBhi5aPqpH2C7l/30A==
+ dependencies:
+ "@microsoft/api-extractor-model" "7.7.11"
+ "@microsoft/tsdoc" "0.12.19"
+ "@rushstack/node-core-library" "3.19.7"
+ "@rushstack/ts-command-line" "4.3.14"
+ colors "~1.2.1"
+ lodash "~4.17.15"
+ resolve "1.8.1"
+ source-map "~0.6.1"
+ typescript "~3.7.2"
+
+"@microsoft/tsdoc@0.12.19":
+ version "0.12.19"
+ resolved "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.12.19.tgz#2173ccb92469aaf62031fa9499d21b16d07f9b57"
+ integrity sha512-IpgPxHrNxZiMNUSXqR1l/gePKPkfAmIKoDRP9hp7OwjU29ZR8WCJsOJ8iBKgw0Qk+pFwR+8Y1cy8ImLY6e9m4A==
+
+"@rushstack/node-core-library@3.19.7":
+ version "3.19.7"
+ resolved "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.19.7.tgz#8d8a193fd6f99536c92dd797ab50fd5fcb7630ea"
+ integrity sha512-gKE/OXH5GAj8yJ1kEyRW68UekJernilZ3QTRgmQ0MUHBCQmtZ9Q6T5PQ1sVbcL4teH8BMdpZeFy1DKnHs8h3PA==
+ dependencies:
+ "@types/node" "10.17.13"
+ colors "~1.2.1"
+ fs-extra "~7.0.1"
+ jju "~1.4.0"
+ semver "~5.3.0"
+ timsort "~0.3.0"
+ z-schema "~3.18.3"
+
+"@rushstack/ts-command-line@4.3.14":
+ version "4.3.14"
+ resolved "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-4.3.14.tgz#5d7a437d4e9c564ff1b8e876215fca96c74858a1"
+ integrity sha512-YJZIyKvkm3f6ZdKSfMntHS9542Y2mmMWzaiPPoXxLFZntKxEIDE3WfUNlvOSo3yK4fNd09Tz3hfvTivQNHSiKQ==
+ dependencies:
+ "@types/argparse" "1.0.33"
+ argparse "~1.0.9"
+ colors "~1.2.1"
+
+"@types/argparse@1.0.33":
+ version "1.0.33"
+ resolved "https://registry.npmjs.org/@types/argparse/-/argparse-1.0.33.tgz#2728669427cdd74a99e53c9f457ca2866a37c52d"
+ integrity sha512-VQgHxyPMTj3hIlq9SY1mctqx+Jj8kpQfoLvDlVSDNOyuYs8JYfkuY3OW/4+dO657yPmNhHpePRx0/Tje5ImNVQ==
+
"@types/node@*", "@types/node@^13.13.0":
version "13.13.0"
resolved "https://registry.npmjs.org/@types/node/-/node-13.13.0.tgz#30d2d09f623fe32cde9cb582c7a6eda2788ce4a8"
integrity sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==
+"@types/node@10.17.13":
+ version "10.17.13"
+ resolved "https://registry.npmjs.org/@types/node/-/node-10.17.13.tgz#ccebcdb990bd6139cd16e84c39dc2fb1023ca90c"
+ integrity sha512-pMCcqU2zT4TjqYFrWtYHKal7Sl30Ims6ulZ4UFXxI4xbtQqK/qqKwkDoBFCfooRqqmRu9vY3xaJRwxSh673aYg==
+
"@types/spdy@^3.4.4":
version "3.4.4"
resolved "https://registry.npmjs.org/@types/spdy/-/spdy-3.4.4.tgz#3282fd4ad8c4603aa49f7017dd520a08a345b2bc"
@@ -33,6 +93,13 @@ already@^1.12.0:
dependencies:
throat "^5.0.0"
+argparse@~1.0.9:
+ version "1.0.10"
+ resolved "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
+ integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
+ dependencies:
+ sprintf-js "~1.0.2"
+
buffer-from@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
@@ -43,6 +110,16 @@ callguard@^1.2.1:
resolved "https://registry.yarnpkg.com/callguard/-/callguard-1.2.1.tgz#3d8df2ea91c946abf1c43b7d6abde23d3aecfdbb"
integrity sha512-QTxtuE+QrPA/ZStfYEf/IL1RqyOEpg3CMKp35oTs4n91WveYjbnbPJ0O2ob+RxhPzOuvb0KgQvYwJzhZ6nswXQ==
+colors@~1.2.1:
+ version "1.2.5"
+ resolved "https://registry.npmjs.org/colors/-/colors-1.2.5.tgz#89c7ad9a374bc030df8013241f68136ed8835afc"
+ integrity sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg==
+
+commander@^2.7.1:
+ version "2.20.3"
+ resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
+ integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
+
core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -92,6 +169,15 @@ fetch-h2@^2.4.5:
to-arraybuffer "^1.0.1"
tough-cookie "^3.0.1"
+fs-extra@~7.0.1:
+ version "7.0.1"
+ resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
+ integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
+ dependencies:
+ graceful-fs "^4.1.2"
+ jsonfile "^4.0.0"
+ universalify "^0.1.0"
+
get-stream@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9"
@@ -99,6 +185,11 @@ get-stream@^5.1.0:
dependencies:
pump "^3.0.0"
+graceful-fs@^4.1.2, graceful-fs@^4.1.6:
+ version "4.2.3"
+ resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423"
+ integrity sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==
+
handle-thing@^2.0.0:
version "2.0.1"
resolved "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
@@ -144,6 +235,33 @@ isarray@~1.0.0:
resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
+jju@~1.4.0:
+ version "1.4.0"
+ resolved "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz#a3abe2718af241a2b2904f84a625970f389ae32a"
+ integrity sha1-o6vicYryQaKykE+EpiWXDzia4yo=
+
+jsonfile@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
+ integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
+ optionalDependencies:
+ graceful-fs "^4.1.6"
+
+lodash.get@^4.0.0:
+ version "4.4.2"
+ resolved "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
+ integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
+
+lodash.isequal@^4.0.0:
+ version "4.5.0"
+ resolved "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
+ integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=
+
+lodash@~4.17.15:
+ version "4.17.15"
+ resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
+ integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
+
minimalistic-assert@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
@@ -182,6 +300,11 @@ open@^7.0.3:
is-docker "^2.0.0"
is-wsl "^2.1.1"
+path-parse@^1.0.5:
+ version "1.0.6"
+ resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
+ integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
+
prettier@^2.0.4:
version "2.0.4"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.0.4.tgz#2d1bae173e355996ee355ec9830a7a1ee05457ef"
@@ -232,6 +355,13 @@ readable-stream@^2.0.1:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
+resolve@1.8.1:
+ version "1.8.1"
+ resolved "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
+ integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==
+ dependencies:
+ path-parse "^1.0.5"
+
safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@@ -247,6 +377,16 @@ select-hose@^2.0.0:
resolved "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
integrity sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo=
+semver@~5.3.0:
+ version "5.3.0"
+ resolved "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
+ integrity sha1-myzl094C0XxgEq0yaqa00M9U+U8=
+
+source-map@~0.6.1:
+ version "0.6.1"
+ resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
+ integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
+
spdy-transport@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/spdy-transport/-/spdy-transport-3.0.0.tgz#00d4863a6400ad75df93361a1608605e5dcdcf31"
@@ -270,6 +410,11 @@ spdy@^4.0.2:
select-hose "^2.0.0"
spdy-transport "^3.0.0"
+sprintf-js@~1.0.2:
+ version "1.0.3"
+ resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
+ integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
+
string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
@@ -296,6 +441,11 @@ through2@^3.0.1:
dependencies:
readable-stream "2 || 3"
+timsort@~0.3.0:
+ version "0.3.0"
+ resolved "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
+ integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=
+
to-arraybuffer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43"
@@ -320,11 +470,26 @@ typescript@^3.8.3:
resolved "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
+typescript@~3.7.2:
+ version "3.7.5"
+ resolved "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae"
+ integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==
+
+universalify@^0.1.0:
+ version "0.1.2"
+ resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
+ integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
+
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
+validator@^8.0.0:
+ version "8.2.0"
+ resolved "https://registry.npmjs.org/validator/-/validator-8.2.0.tgz#3c1237290e37092355344fef78c231249dab77b9"
+ integrity sha512-Yw5wW34fSv5spzTXNkokD6S6/Oq92d8q/t14TqsS3fAiA1RYnxSFSIZ+CY3n6PGGRCq5HhJTSepQvFUS2QUDxA==
+
wbuf@^1.1.0, wbuf@^1.7.3:
version "1.7.3"
resolved "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz#c1d8d149316d3ea852848895cb6a0bfe887b87df"
@@ -341,3 +506,14 @@ ws@^7.2.3:
version "7.2.3"
resolved "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46"
integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==
+
+z-schema@~3.18.3:
+ version "3.18.4"
+ resolved "https://registry.npmjs.org/z-schema/-/z-schema-3.18.4.tgz#ea8132b279533ee60be2485a02f7e3e42541a9a2"
+ integrity sha512-DUOKC/IhbkdLKKiV89gw9DUauTV8U/8yJl1sjf6MtDmzevLKOF2duNJ495S3MFVjqZarr+qNGCPbkg4mu4PpLw==
+ dependencies:
+ lodash.get "^4.0.0"
+ lodash.isequal "^4.0.0"
+ validator "^8.0.0"
+ optionalDependencies:
+ commander "^2.7.1"
From 09a1c570ab1e0f8b37f7e9f3c8cedce271ed805e Mon Sep 17 00:00:00 2001
From: masx200 <34191203+masx200@users.noreply.github.com>
Date: Tue, 21 Apr 2020 18:41:43 +0800
Subject: [PATCH 125/125] Update LICENSE
---
LICENSE | 694 +++-----------------------------------------------------
1 file changed, 31 insertions(+), 663 deletions(-)
diff --git a/LICENSE b/LICENSE
index e72bfdd..51decc2 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,674 +1,42 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
+The MIT License (MIT)
- Preamble
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
+特此授予获得副本的任何人免费的许可
+本软件和相关文档文件(以下简称“软件”)
+不受限制地处理软件,包括但不限于
+使用,复制,修改,合并,发布,分发,再许可和/或授权的权利
+出售本软件的副本,并允许本软件所涉及的人
+具备以下条件:
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
+上述版权声明和此许可声明应包含在
+软件的所有副本或实质性部分。
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
+本软件按“原样”提供,没有任何形式的明示或明示担保。
+暗示(包括但不限于对适销性的保证),
+适用于特定目的和非侵权。在任何情况下都不会
+作者或版权持有人对任何索赔,损害或其他责任
+无论是在合同,侵权或其他情况下的责任
+来自,与软件或使用或其他交易有关的,与之相关的
+在软件中。
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- Copyright (C)
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-.
\ No newline at end of file