Repository: asciimoo/wuzz
Branch: master
Commit: 791aeb93a880
Files: 24
Total size: 130.5 KB
Directory structure:
gitextract_9scu9mfj/
├── .dockerignore
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── Dockerfile
├── LICENSE
├── README.md
├── _config.yml
├── commands.go
├── config/
│ └── config.go
├── docker-entrypoint.sh
├── formatter/
│ ├── binary.go
│ ├── formatter.go
│ ├── formatter_test.go
│ ├── html.go
│ ├── json.go
│ └── text.go
├── go.mod
├── go.sum
├── keys.go
├── request-headers.go
├── sample-config.toml
├── status-line.go
└── wuzz.go
================================================
FILE CONTENTS
================================================
================================================
FILE: .dockerignore
================================================
**
!config
!formatter
!*.go
!go.mod
!sample-config.toml
!docker-entrypoint.sh
================================================
FILE: .gitignore
================================================
wuzz
================================================
FILE: .travis.yml
================================================
language: go
go:
- 1.12.x #Update go version
- tip
os:
- linux
# remove osx, getting vm from travis is extremely slow
# - osx
arch:
- amd64
- ppc64le
env:
- "PATH=/home/travis/gopath/bin:$PATH"
script:
- test -z "$(go get -a)"
- test -z "$(gofmt -l ./)"
- test -z "$(go vet -v ./...)"
- go test ./...
- go build
# after_success:
# # Publish as pre-release if it isn't a pull request
# - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then go get github.com/mitchellh/gox && go get github.com/tcnksm/ghr; fi'
# - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then gox -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" && ghr --username $GITHUB_USERNAME --token $GITHUB_TOKEN --replace --prerelease --debug pre-release dist/; fi'
================================================
FILE: CHANGELOG.md
================================================
## 0.5.0 2020.01.19
- Added context specific search for HTML (goquery)
- Request data displayed in request history
- Fixed JSON indentation
- Redirect toggle command Added
- Multiple minor bug fixes
## 0.4.0 2017.08.21
- Save/load requests (`-f`/`--file` flags for loading)
- Multipart form handling (`-F`/`--form` flags)
- Edit window content in external editor
- Colorized html output
- Context specific search (github.com/tidwall/gjson for JSON)
- More consistency with cURL API (`--data-urlencode` flag added)
- Update to the latest `gocui` ui library
## 0.3.0 2017.03.07
- Request header autocompletion
- Configurable statusline
- JSON requests with `-j`/`--json` flags
- Allow insecure HTTPS requests (`-k`/`--insecure` flags)
- Socks proxy support (`-x`/`--proxy` flags)
- Disable following redirects (`-R`/`--disable-redirects` flags)
- Enhanced TLS support (`-T`/`--tls`, `-1`/`--tlsv1`, `--tlsv1.0`, `--tlsv1.1`, `--tlsv1.2` flags)
- Commands for line and word deletion
- Home/end navigation fix
## 0.2.0 2017.02.18
- Config file support with configurable keybindings
- Help popup (F1 key)
- Ignore invalid SSL certs with the --insecure flag
- PATCH request support
- Allow JSON request body (--data-binary flag)
- Colorized JSON response
- Parameter encoding bugfix
- Multiple UI bugfixes
## 0.1.0 2017.02.11
Initial release
================================================
FILE: Dockerfile
================================================
FROM alpine:3.12 AS permissions-giver
# Make sure docker-entrypoint.sh is executable, regardless of the build host.
WORKDIR /out
COPY docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh
FROM golang:1.14-alpine3.12 AS builder
# Build wuzz
WORKDIR /out
COPY . .
RUN go build .
FROM alpine:3.12 AS organizer
# Prepare executables
WORKDIR /out
COPY --from=builder /out/wuzz .
COPY --from=permissions-giver /out/docker-entrypoint.sh .
FROM alpine:3.12 AS runner
WORKDIR /wuzz
COPY --from=organizer /out /usr/local/bin
ENTRYPOINT [ "docker-entrypoint.sh" ]
================================================
FILE: LICENSE
================================================
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are 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.
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.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
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 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 work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero 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 Affero 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 Affero 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 Affero 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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
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 AGPL, see
<http://www.gnu.org/licenses/>.
================================================
FILE: README.md
================================================
# wuzz
Interactive cli tool for HTTP inspection.
Wuzz command line arguments are similar to cURL's arguments,
so it can be used to inspect/modify requests copied from the
browser's network inspector with the "copy as cURL" feature.

## Installation and usage
### GO
```
$ go get github.com/asciimoo/wuzz
$ "$GOPATH/bin/wuzz" --help
```
Note: golang >= 1.10 required.
[Binary releases](https://github.com/asciimoo/wuzz/releases) are also available.
### Apt
```
$ apt install wuzz
```
### Apk
```
$ apk add wuzz
```
### Scoop
```
$ scoop bucket add main
$ scoop install main/wuzz
```
### X-CMD
```
$ x env use wuzz
```
### Nix
```
$ nix-shell -p wuzz
```
### Configuration
It is possible to override default settings in a configuration file.
The default location is `"$XDG_CONFIG_HOME/wuzz/config.toml"`on linux
and `~/.wuzz/config.toml` on other platforms.
`-c`/`--config` switches can be used to load config file from custom location.
See [example configuration](sample-config.toml) for more details.
### Commands
Keybinding | Description
----------------------------------------|---------------------------------------
<kbd>F1</kbd> | Display help
<kbd>Ctrl+R</kbd> | Send request
<kbd>Ret</kbd> | Send request (only from URL view)
<kbd>Ctrl+S</kbd> | Save response
<kbd>Ctrl+E</kbd> | Save request
<kbd>Ctrl+F</kbd> | Load request
<kbd>Ctrl+C</kbd> | Quit
<kbd>Ctrl+K</kbd>, <kbd>Shift+Tab</kbd> | Previous view
<kbd>Ctlr+J</kbd>, <kbd>Tab</kbd> | Next view
<kbd>Ctlr+T</kbd> | Toggle context specific search
<kbd>Ctrl+L</kbd> | Clear all tabs to default
<kbd>Alt+H</kbd> | Toggle history
<kbd>Down</kbd> | Move down one view line
<kbd>Up</kbd> | Move up one view line
<kbd>Page down</kbd> | Move down one view page
<kbd>Page up</kbd> | Move up one view page
<kbd>F2</kbd> | Jump to URL
<kbd>F3</kbd> | Jump to query parameters
<kbd>F4</kbd> | Jump to HTTP method
<kbd>F5</kbd> | Jump to request body
<kbd>F6</kbd> | Jump to headers
<kbd>F7</kbd> | Jump to search
<kbd>F8</kbd> | Jump to response headers
<kbd>F9</kbd> | Jump to response body
<kbd>F11</kbd> | Redirects Restriction Mode
### Context specific search
Wuzz accepts regular expressions by default to filter response body.
Custom query syntax can be toggled by pressing <kbd>Ctrl+T</kbd>.
The following formats have context specific search syntax:
Response format | Query syntax
-----------------|----------------------------------------
HTML | https://github.com/PuerkitoBio/goquery
JSON | https://github.com/tidwall/gjson
## TODO
* Better navigation
* Autocompletion
* Tests
## Bugs / Suggestions
Bugs or suggestions? Visit the [issue tracker](https://github.com/asciimoo/wuzz/issues)
or join `#wuzz` on freenode
================================================
FILE: _config.yml
================================================
theme: jekyll-theme-cayman
================================================
FILE: commands.go
================================================
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"unicode"
"github.com/awesome-gocui/gocui"
)
type CommandFunc func(*gocui.Gui, *gocui.View) error
var COMMANDS map[string]func(string, *App) CommandFunc = map[string]func(string, *App) CommandFunc{
"submit": func(_ string, a *App) CommandFunc {
return a.SubmitRequest
},
"saveResponse": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
return a.OpenSaveDialog(VIEW_TITLES[SAVE_RESPONSE_DIALOG_VIEW], g,
func(g *gocui.Gui, _ *gocui.View) error {
saveLocation := getViewValue(g, SAVE_DIALOG_VIEW)
if len(a.history) == 0 {
return nil
}
req := a.history[a.historyIndex]
if req.RawResponseBody == nil {
return nil
}
err := ioutil.WriteFile(saveLocation, req.RawResponseBody, 0644)
var saveResult string
if err == nil {
saveResult = "Response saved successfully."
} else {
saveResult = "Error saving response: " + err.Error()
}
viewErr := a.OpenSaveResultView(saveResult, g)
return viewErr
})
}
},
"loadRequest": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
return a.OpenSaveDialog(VIEW_TITLES[LOAD_REQUEST_DIALOG_VIEW], g,
func(g *gocui.Gui, _ *gocui.View) error {
defer a.closePopup(g, SAVE_DIALOG_VIEW)
loadLocation := getViewValue(g, SAVE_DIALOG_VIEW)
return a.LoadRequest(g, loadLocation)
})
}
},
"saveRequest": func(_ string, a *App) CommandFunc {
return a.SaveRequest
},
"history": func(_ string, a *App) CommandFunc {
return a.ToggleHistory
},
"quit": func(_ string, _ *App) CommandFunc {
return quit
},
"focus": func(args string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
return a.setViewByName(g, args)
}
},
"nextView": func(_ string, a *App) CommandFunc {
return a.NextView
},
"prevView": func(_ string, a *App) CommandFunc {
return a.PrevView
},
"scrollDown": func(_ string, _ *App) CommandFunc {
return scrollViewDown
},
"scrollUp": func(_ string, _ *App) CommandFunc {
return scrollViewUp
},
"pageDown": func(_ string, _ *App) CommandFunc {
return pageDown
},
"pageUp": func(_ string, _ *App) CommandFunc {
return pageUp
},
"deleteLine": func(_ string, _ *App) CommandFunc {
return deleteLine
},
"deleteWord": func(_ string, _ *App) CommandFunc {
return deleteWord
},
"openEditor": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, v *gocui.View) error {
return openEditor(g, v, a.config.General.Editor)
}
},
"toggleContextSpecificSearch": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
a.config.General.ContextSpecificSearch = !a.config.General.ContextSpecificSearch
a.PrintBody(g)
return nil
}
},
"clearHistory": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
a.history = make([]*Request, 0, 31)
a.historyIndex = 0
a.Layout(g)
return nil
}
},
"redirectRestriction": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
a.config.General.FollowRedirects = !a.config.General.FollowRedirects
return nil
}
},
"clearTabs": func(_ string, a *App) CommandFunc {
return func(g *gocui.Gui, _ *gocui.View) error {
if a.currentPopup != "" {
return nil
}
a.restoreRequest(g, 0, true)
g.SetCurrentView(URL_VIEW)
return nil
}
},
}
func scrollView(v *gocui.View, dy int) error {
v.Autoscroll = false
ox, oy := v.Origin()
if oy+dy < 0 {
dy = -oy
}
if _, err := v.Line(dy); dy > 0 && err != nil {
dy = 0
}
v.SetOrigin(ox, oy+dy)
return nil
}
func scrollViewUp(_ *gocui.Gui, v *gocui.View) error {
return scrollView(v, -1)
}
func scrollViewDown(_ *gocui.Gui, v *gocui.View) error {
return scrollView(v, 1)
}
func pageUp(_ *gocui.Gui, v *gocui.View) error {
_, height := v.Size()
scrollView(v, -height*2/3)
return nil
}
func pageDown(_ *gocui.Gui, v *gocui.View) error {
_, height := v.Size()
scrollView(v, height*2/3)
return nil
}
func deleteLine(_ *gocui.Gui, v *gocui.View) error {
if !v.Editable {
return nil
}
_, curY := v.Cursor()
_, oY := v.Origin()
currentLine := curY + oY
viewLines := strings.Split(strings.TrimSpace(v.Buffer()), "\n")
if currentLine >= len(viewLines) {
return nil
}
v.Clear()
if currentLine > 0 {
fmt.Fprintln(v, strings.Join(viewLines[:currentLine], "\n"))
}
fmt.Fprint(v, strings.Join(viewLines[currentLine+1:], "\n"))
v.SetCursor(0, currentLine)
v.SetOrigin(0, oY)
return nil
}
func deleteWord(_ *gocui.Gui, v *gocui.View) error {
cX, cY := v.Cursor()
oX, _ := v.Origin()
cX = cX - 1 + oX
line, err := v.Line(cY)
if err != nil || line == "" || cX < 0 {
return nil
}
if cX >= len(line) {
cX = len(line) - 1
}
origCharCateg := getCharCategory(rune(line[cX]))
v.EditDelete(true)
cX -= 1
for cX >= 0 {
c := rune(line[cX])
if origCharCateg != getCharCategory(c) {
break
}
v.EditDelete(true)
cX -= 1
}
return nil
}
func getCharCategory(chr rune) int {
switch {
case unicode.IsDigit(chr):
return 0
case unicode.IsLetter(chr):
return 1
case unicode.IsSpace(chr):
return 2
case unicode.IsPunct(chr):
return 3
}
return int(chr)
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
func openEditor(g *gocui.Gui, v *gocui.View, editor string) error {
file, err := ioutil.TempFile(os.TempDir(), "wuzz-")
if err != nil {
return nil
}
defer os.Remove(file.Name())
val := getViewValue(g, v.Name())
if val != "" {
fmt.Fprint(file, val)
}
file.Close()
info, err := os.Stat(file.Name())
if err != nil {
return nil
}
gocui.Suspend()
cmd := exec.Command(editor, file.Name())
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err = cmd.Run()
gocui.Resume()
// sync termbox to reset console settings
// this is required because the external editor can modify the console
defer g.Update(func(gui *gocui.Gui) error {
return nil
})
if err != nil {
rv, _ := g.View(RESPONSE_BODY_VIEW)
rv.Clear()
fmt.Fprintf(rv, "Editor open error: %v", err)
return nil
}
newInfo, err := os.Stat(file.Name())
if err != nil || newInfo.ModTime().Before(info.ModTime()) {
return nil
}
newVal, err := ioutil.ReadFile(file.Name())
if err != nil {
return nil
}
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
v.Clear()
fmt.Fprint(v, strings.TrimSpace(string(newVal)))
return nil
}
================================================
FILE: config/config.go
================================================
package config
import (
"errors"
"os"
"path/filepath"
"runtime"
"time"
"github.com/BurntSushi/toml"
"github.com/mitchellh/go-homedir"
)
var ContentTypes = map[string]string{
"json": "application/json",
"form": "application/x-www-form-urlencoded",
"multipart": "multipart/form-data",
}
// Duration is used to automatically unmarshal timeout strings to
// time.Duration values
type Duration struct {
time.Duration
}
func (d *Duration) UnmarshalText(text []byte) error {
var err error
d.Duration, err = time.ParseDuration(string(text))
return err
}
type Config struct {
General GeneralOptions
Keys map[string]map[string]string
}
type GeneralOptions struct {
ContextSpecificSearch bool
DefaultURLScheme string
Editor string
FollowRedirects bool
FormatJSON bool
Insecure bool
PreserveScrollPosition bool
StatusLine string
TLSVersionMax uint16
TLSVersionMin uint16
Timeout Duration
}
var defaultTimeoutDuration, _ = time.ParseDuration("1m")
var DefaultKeys = map[string]map[string]string{
"global": {
"CtrlR": "submit",
"CtrlC": "quit",
"CtrlS": "saveResponse",
"CtrlF": "loadRequest",
"CtrlE": "saveRequest",
"CtrlD": "deleteLine",
"CtrlW": "deleteWord",
"CtrlO": "openEditor",
"CtrlT": "toggleContextSpecificSearch",
"CtrlX": "clearHistory",
"CtrlL": "clearTabs",
"Tab": "nextView",
"CtrlJ": "nextView",
"CtrlK": "prevView",
"AltH": "history",
"F2": "focus url",
"F3": "focus get",
"F4": "focus method",
"F5": "focus data",
"F6": "focus headers",
"F7": "focus search",
"F8": "focus response-headers",
"F9": "focus response-body",
"F11": "redirectRestriction",
},
"url": {
"Enter": "submit",
},
"response-headers": {
"ArrowUp": "scrollUp",
"ArrowDown": "scrollDown",
"PageUp": "pageUp",
"PageDown": "pageDown",
},
"response-body": {
"ArrowUp": "scrollUp",
"ArrowDown": "scrollDown",
"PageUp": "pageUp",
"PageDown": "pageDown",
},
"help": {
"ArrowUp": "scrollUp",
"ArrowDown": "scrollDown",
"PageUp": "pageUp",
"PageDown": "pageDown",
},
}
var DefaultConfig = Config{
General: GeneralOptions{
DefaultURLScheme: "https",
Editor: "vim",
FollowRedirects: true,
FormatJSON: true,
Insecure: false,
PreserveScrollPosition: true,
StatusLine: "[wuzz {{.Version}}]{{if .Duration}} [Response time: {{.Duration}}]{{end}} [Request no.: {{.RequestNumber}}/{{.HistorySize}}] [Search type: {{.SearchType}}]{{if .DisableRedirect}} [Redirects Restricted Mode {{.DisableRedirect}}]{{end}}",
Timeout: Duration{
defaultTimeoutDuration,
},
},
}
func init() {
if os.Getenv("EDITOR") != "" {
DefaultConfig.General.Editor = os.Getenv("EDITOR")
}
}
func LoadConfig(configFile string) (*Config, error) {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
return nil, errors.New("Config file does not exist.")
} else if err != nil {
return nil, err
}
conf := DefaultConfig
if _, err := toml.DecodeFile(configFile, &conf); err != nil {
return nil, err
}
if conf.Keys == nil {
conf.Keys = DefaultKeys
} else {
// copy default keys
for keyCategory, keys := range DefaultKeys {
confKeys, found := conf.Keys[keyCategory]
if found {
for key, action := range keys {
if _, found := confKeys[key]; !found {
conf.Keys[keyCategory][key] = action
}
}
} else {
conf.Keys[keyCategory] = keys
}
}
}
return &conf, nil
}
func GetDefaultConfigLocation() string {
var configFolderLocation string
switch runtime.GOOS {
case "linux":
// Use the XDG_CONFIG_HOME variable if it is set, otherwise
// $HOME/.config/wuzz/config.toml
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
if xdgConfigHome != "" {
configFolderLocation = xdgConfigHome
} else {
configFolderLocation, _ = homedir.Expand("~/.config/wuzz/")
}
default:
// On other platforms we just use $HOME/.wuzz
configFolderLocation, _ = homedir.Expand("~/.wuzz/")
}
return filepath.Join(configFolderLocation, "config.toml")
}
================================================
FILE: docker-entrypoint.sh
================================================
#!/bin/sh
set -e
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then
sleep 0.01
set -- wuzz "$@"
fi
exec "$@"
================================================
FILE: formatter/binary.go
================================================
package formatter
import (
"encoding/hex"
"errors"
"fmt"
"io"
)
type binaryFormatter struct {
}
func (f *binaryFormatter) Format(writer io.Writer, data []byte) error {
fmt.Fprint(writer, hex.Dump(data))
return nil
}
func (f *binaryFormatter) Title() string {
return "[binary]"
}
func (f *binaryFormatter) Searchable() bool {
return false
}
func (f *binaryFormatter) Search(q string, body []byte) ([]string, error) {
return nil, errors.New("Cannot perform search on binary content type")
}
================================================
FILE: formatter/formatter.go
================================================
package formatter
import (
"io"
"mime"
"strings"
"github.com/asciimoo/wuzz/config"
)
type ResponseFormatter interface {
Format(writer io.Writer, data []byte) error
Title() string
Searchable() bool
Search(string, []byte) ([]string, error)
}
func New(appConfig *config.Config, contentType string) ResponseFormatter {
ctype, _, err := mime.ParseMediaType(contentType)
if err == nil && appConfig.General.FormatJSON && (ctype == config.ContentTypes["json"] || strings.HasSuffix(ctype, "+json")) {
return &jsonFormatter{}
} else if strings.Contains(contentType, "text/html") {
return &htmlFormatter{}
} else if strings.Index(contentType, "text") == -1 && strings.Index(contentType, "application") == -1 {
return &binaryFormatter{}
} else {
return &TextFormatter{}
}
}
================================================
FILE: formatter/formatter_test.go
================================================
package formatter
import (
"bytes"
"testing"
"github.com/asciimoo/wuzz/config"
"github.com/nwidger/jsoncolor"
"github.com/x86kernel/htmlcolor"
)
func TestFormat(t *testing.T) {
var binBuffer bytes.Buffer
New(configFixture(true), "octet-stream").Format(&binBuffer, []byte("some binary data"))
if binBuffer.String() != "00000000 73 6f 6d 65 20 62 69 6e 61 72 79 20 64 61 74 61 |some binary data|\n" {
t.Error("Expected binary to eq " + binBuffer.String())
}
var htmlBuffer bytes.Buffer
New(configFixture(true), "text/html; charset=utf-8").Format(&htmlBuffer, []byte("<html><span>unfomatted</span></html>"))
var htmltargetBuffer bytes.Buffer
htmlcolor.NewFormatter().Format(&htmltargetBuffer, []byte("<html><span>unfomatted</span></html>"))
htmltarget := htmltargetBuffer.String()
if htmlBuffer.String() != htmltarget {
t.Error("Expected html to eq " + htmlBuffer.String())
}
var jsonEnabledBuffer bytes.Buffer
New(configFixture(true), "application/json; charset=utf-8").Format(&jsonEnabledBuffer, []byte("{\"json\": \"some value\"}"))
var jsontargetBuffer bytes.Buffer
f := jsoncolor.NewFormatter()
f.Indent = " "
f.Format(&jsontargetBuffer, []byte("{\"json\": \"some value\"}"))
jsontarget := jsontargetBuffer.String()
if jsonEnabledBuffer.String() != jsontarget {
t.Error("Expected json to eq \n" + jsonEnabledBuffer.String() + "\nbut not\n" + jsontarget)
}
var jsonDisabledBuffer bytes.Buffer
New(configFixture(false), "application/json; charset=utf-8").Format(&jsonDisabledBuffer, []byte("{\"json\": \"some value\"}"))
if jsonDisabledBuffer.String() != "{\"json\": \"some value\"}" {
t.Error("Expected json to eq " + jsonDisabledBuffer.String())
}
var textBuffer bytes.Buffer
New(configFixture(true), "text/html; charset=utf-8").Format(&textBuffer, []byte("some text"))
if textBuffer.String() != "some text" {
t.Error("Expected text to eq " + textBuffer.String())
}
}
func TestTitle(t *testing.T) {
//binary
title := New(configFixture(true), "octet-stream").Title()
if title != "[binary]" {
t.Error("for octet-stream content type expected title ", title, "to be [binary]")
}
//html
title = New(configFixture(true), "text/html; charset=utf-8").Title()
if title != "[html]" {
t.Error("For text/html content type expected title ", title, " to be [html]")
}
//json
title = New(configFixture(true), "application/json; charset=utf-8").Title()
if title != "[json]" {
t.Error("For text/html content type expected title ", title, " to be [json]")
}
//text
title = New(configFixture(true), "text/plain; charset=utf-8").Title()
if title != "[text]" {
t.Error("For text/html content type expected title ", title, " to be [text]")
}
}
func TestSearchable(t *testing.T) {
if New(configFixture(true), "octet-stream").Searchable() {
t.Error("binary file can't be searchable")
}
if !New(configFixture(true), "text/html").Searchable() {
t.Error("text/html should be searchable")
}
if !New(configFixture(true), "application/json").Searchable() {
t.Error("application/json should be searchable")
}
if !New(configFixture(true), "text/plain").Searchable() {
t.Error("text/plain should be searchable")
}
}
func configFixture(jsonEnabled bool) *config.Config {
return &config.Config{
General: config.GeneralOptions{
FormatJSON: jsonEnabled,
},
}
}
================================================
FILE: formatter/html.go
================================================
package formatter
import (
"bytes"
"errors"
"io"
"github.com/PuerkitoBio/goquery"
"github.com/x86kernel/htmlcolor"
)
type htmlFormatter struct {
parsedBody goquery.Document
TextFormatter
}
func (f *htmlFormatter) Format(writer io.Writer, data []byte) error {
htmlFormatter := htmlcolor.NewFormatter()
buf := bytes.NewBuffer(make([]byte, 0, len(data)))
err := htmlFormatter.Format(buf, data)
if err == io.EOF {
writer.Write(buf.Bytes())
return nil
}
return errors.New("html formatter error")
}
func (f *htmlFormatter) Title() string {
return "[html]"
}
func (f *htmlFormatter) Search(q string, body []byte) ([]string, error) {
if q == "" {
buf := bytes.NewBuffer(make([]byte, 0, len(body)))
err := f.Format(buf, body)
return []string{buf.String()}, err
}
doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(body))
if err != nil {
return nil, err
}
results := make([]string, 0, 8)
doc.Find(q).Each(func(_ int, s *goquery.Selection) {
htmlResult, err := goquery.OuterHtml(s)
if err == nil {
results = append(results, htmlResult)
}
})
return results, nil
}
================================================
FILE: formatter/json.go
================================================
package formatter
import (
"bytes"
"errors"
"io"
"github.com/nwidger/jsoncolor"
"github.com/tidwall/gjson"
)
type jsonFormatter struct {
parsedBody gjson.Result
TextFormatter
}
func (f *jsonFormatter) Format(writer io.Writer, data []byte) error {
jsonFormatter := jsoncolor.NewFormatter()
jsonFormatter.Indent = " "
buf := bytes.NewBuffer(make([]byte, 0, len(data)))
err := jsonFormatter.Format(buf, data)
if err == nil {
writer.Write(buf.Bytes())
return nil
}
return errors.New("json formatter error")
}
func (f *jsonFormatter) Title() string {
return "[json]"
}
func (f *jsonFormatter) Search(q string, body []byte) ([]string, error) {
if q != "" {
if f.parsedBody.Type != gjson.JSON {
f.parsedBody = gjson.ParseBytes(body)
}
searchResult := f.parsedBody.Get(q)
if searchResult.Type == gjson.Null {
return nil, errors.New("Invalid gjson query or no results found")
}
if searchResult.Type != gjson.JSON {
return []string{searchResult.String()}, nil
}
body = []byte(searchResult.String())
}
jsonFormatter := jsoncolor.NewFormatter()
jsonFormatter.Indent = " "
buf := bytes.NewBuffer(make([]byte, 0, len(body)))
err := jsonFormatter.Format(buf, body)
if err != nil {
return nil, errors.New("Invalid results")
}
return []string{string(buf.Bytes())}, nil
}
================================================
FILE: formatter/text.go
================================================
package formatter
import (
"io"
"regexp"
)
type TextFormatter struct {
}
func (f *TextFormatter) Format(writer io.Writer, data []byte) error {
_, err := writer.Write(data)
return err
}
func (f *TextFormatter) Title() string {
return "[text]"
}
func (f *TextFormatter) Searchable() bool {
return true
}
func (f *TextFormatter) Search(q string, body []byte) ([]string, error) {
search_re, err := regexp.Compile(q)
if err != nil {
return nil, err
}
ret := make([]string, 0, 16)
for _, match := range search_re.FindAll(body, 1000) {
ret = append(ret, string(match))
}
return ret, nil
}
================================================
FILE: go.mod
================================================
module github.com/asciimoo/wuzz
go 1.24.0
toolchain go1.24.7
require (
github.com/BurntSushi/toml v1.5.0
github.com/PuerkitoBio/goquery v1.10.3
github.com/alessio/shellescape v1.4.2
github.com/awesome-gocui/gocui v1.1.0
github.com/mattn/go-runewidth v0.0.19
github.com/mitchellh/go-homedir v1.1.0
github.com/nwidger/jsoncolor v0.3.2
github.com/tidwall/gjson v1.18.0
github.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0
golang.org/x/net v0.46.0
)
require (
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/gdamore/tcell/v2 v2.9.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/tools v0.37.0 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
================================================
FILE: go.sum
================================================
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
github.com/alessio/shellescape v1.2.2 h1:8LnL+ncxhWT2TR00dfJRT25JWWrhkMZXneHVWnetDZg=
github.com/alessio/shellescape v1.2.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=
github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
github.com/awesome-gocui/gocui v1.1.0 h1:db2j7yFEoHZjpQFeE2xqiatS8bm1lO3THeLwE6MzOII=
github.com/awesome-gocui/gocui v1.1.0/go.mod h1:M2BXkrp7PR97CKnPRT7Rk0+rtswChPtksw/vRAESGpg=
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM=
github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.9.0 h1:N6t+eqK7/xwtRPwxzs1PXeRWnm0H9l02CrgJ7DLn1ys=
github.com/gdamore/tcell/v2 v2.9.0/go.mod h1:8/ZoqM9rxzYphT9tH/9LnunhV9oPBqwS8WHGYm5nrmo=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/nwidger/jsoncolor v0.3.0 h1:VdTH8Dc0SJoq4pJ8pRxxFZW0/5Ng5akbN4YToCBJDSU=
github.com/nwidger/jsoncolor v0.3.0/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=
github.com/nwidger/jsoncolor v0.3.2 h1:rVJJlwAWDJShnbTYOQ5RM7yTA20INyKXlJ/fg4JMhHQ=
github.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM=
github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=
github.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0 h1:eViiK7U+LXJuAEcnOdp+5jIDp7j9iE2FE8YfWoLExTE=
github.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0/go.mod h1:pUZuomyrQzbA0SQPSwAnDB3TgChnUMfZnSSfcAzpVh8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053/go.mod h1:+nZKN+XVh4LCiA9DV3ywrzN4gumyCnKjau3NGb9SGoE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
================================================
FILE: keys.go
================================================
package main
import (
"github.com/awesome-gocui/gocui"
)
var KEYS = map[string]gocui.Key{
"F1": gocui.KeyF1,
"F2": gocui.KeyF2,
"F3": gocui.KeyF3,
"F4": gocui.KeyF4,
"F5": gocui.KeyF5,
"F6": gocui.KeyF6,
"F7": gocui.KeyF7,
"F8": gocui.KeyF8,
"F9": gocui.KeyF9,
"F10": gocui.KeyF10,
"F11": gocui.KeyF11,
"F12": gocui.KeyF12,
"Insert": gocui.KeyInsert,
"Delete": gocui.KeyDelete,
"Home": gocui.KeyHome,
"End": gocui.KeyEnd,
"PageUp": gocui.KeyPgup,
"PageDown": gocui.KeyPgdn,
"ArrowUp": gocui.KeyArrowUp,
"ArrowDown": gocui.KeyArrowDown,
"ArrowLeft": gocui.KeyArrowLeft,
"ArrowRight": gocui.KeyArrowRight,
"CtrlTilde": gocui.KeyCtrlTilde,
"Ctrl2": gocui.KeyCtrl2,
"CtrlSpace": gocui.KeyCtrlSpace,
"CtrlA": gocui.KeyCtrlA,
"CtrlB": gocui.KeyCtrlB,
"CtrlC": gocui.KeyCtrlC,
"CtrlD": gocui.KeyCtrlD,
"CtrlE": gocui.KeyCtrlE,
"CtrlF": gocui.KeyCtrlF,
"CtrlG": gocui.KeyCtrlG,
"Backspace": gocui.KeyBackspace,
"CtrlH": gocui.KeyCtrlH,
"Tab": gocui.KeyTab,
"CtrlI": gocui.KeyCtrlI,
"CtrlJ": gocui.KeyCtrlJ,
"CtrlK": gocui.KeyCtrlK,
"CtrlL": gocui.KeyCtrlL,
"Enter": gocui.KeyEnter,
"CtrlM": gocui.KeyCtrlM,
"CtrlN": gocui.KeyCtrlN,
"CtrlO": gocui.KeyCtrlO,
"CtrlP": gocui.KeyCtrlP,
"CtrlQ": gocui.KeyCtrlQ,
"CtrlR": gocui.KeyCtrlR,
"CtrlS": gocui.KeyCtrlS,
"CtrlT": gocui.KeyCtrlT,
"CtrlU": gocui.KeyCtrlU,
"CtrlV": gocui.KeyCtrlV,
"CtrlW": gocui.KeyCtrlW,
"CtrlX": gocui.KeyCtrlX,
"CtrlY": gocui.KeyCtrlY,
"CtrlZ": gocui.KeyCtrlZ,
"Esc": gocui.KeyEsc,
"CtrlLsqBracket": gocui.KeyCtrlLsqBracket,
"Ctrl3": gocui.KeyCtrl3,
"Ctrl4": gocui.KeyCtrl4,
"CtrlBackslash": gocui.KeyCtrlBackslash,
"Ctrl5": gocui.KeyCtrl5,
"CtrlRsqBracket": gocui.KeyCtrlRsqBracket,
"Ctrl6": gocui.KeyCtrl6,
"Ctrl7": gocui.KeyCtrl7,
"CtrlSlash": gocui.KeyCtrlSlash,
"CtrlUnderscore": gocui.KeyCtrlUnderscore,
"Space": gocui.KeySpace,
"Backspace2": gocui.KeyBackspace2,
"Ctrl8": gocui.KeyCtrl8,
}
================================================
FILE: request-headers.go
================================================
package main
var REQUEST_HEADERS = []string{
"Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Accept-Datetime",
"Authorization",
"Cache-Control",
"Connection",
"Cookie",
"Content-Length",
"Content-MD5",
"Content-Type",
"Date",
"Expect",
"Forwarded",
"From",
"Host",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
"Max-Forwards",
"Origin",
"Pragma",
"Proxy-Authorization",
"Range",
"Referer",
"TE",
"User-Agent",
"Upgrade",
"Via",
"Warning",
}
================================================
FILE: sample-config.toml
================================================
[general]
timeout = "1m"
formatJSON = true
insecure = false
preserveScrollPosition = true
followRedirects = true
defaultURLScheme = "https"
statusLine = "[wuzz {{.Version}}] [Response time: {{.Duration}}]"
editor = "vim"
# KEYBINDINGS
[keys.global]
CtrlR = "submit"
CtrlC = "quit"
CtrlS = "saveResponse"
CtrlD = "deleteLine"
CtrlW = "deleteWord"
CtrlF = "loadRequest"
CtrlE = "saveRequest"
CtrlT = "toggleContextSpecificSearch"
CtrlX = "clearHistory"
CtrlL = "clearTabs"
Tab = "nextView"
CtrlJ = "nextView"
CtrlK = "prevView"
AltH = "history"
F2 = "focus url"
F3 = "focus get"
F4 = "focus method"
F5 = "focus data"
F6 = "focus headers"
F7 = "focus search"
F8 = "focus response-headers"
F9 = "focus response-body"
F11 = "redirectRestriction"
[keys.url]
Enter = "submit"
[keys.response-headers]
ArrowUp = "scrollUp"
ArrowDown = "scrollDown"
PageUp = "pageUp"
PageDown = "pageDown"
[keys.response-body]
ArrowUp = "scrollUp"
ArrowDown = "scrollDown"
PageUp = "pageUp"
PageDown = "pageDown"
[keys.help]
ArrowUp = "scrollUp"
ArrowDown = "scrollDown"
PageUp = "pageUp"
PageDown = "pageDown"
================================================
FILE: status-line.go
================================================
package main
import (
"fmt"
"strconv"
"text/template"
"github.com/awesome-gocui/gocui"
)
type StatusLine struct {
tpl *template.Template
}
type StatusLineFunctions struct {
app *App
}
func (_ *StatusLineFunctions) Version() string {
return VERSION
}
func (s *StatusLineFunctions) Duration() string {
if len(s.app.history) == 0 {
return ""
}
return s.app.history[s.app.historyIndex].Duration.String()
}
func (s *StatusLineFunctions) HistorySize() string {
return strconv.Itoa(len(s.app.history))
}
func (s *StatusLineFunctions) RequestNumber() string {
i := s.app.historyIndex
if len(s.app.history) > 0 {
i += 1
}
return strconv.Itoa(i)
}
func (s *StatusLineFunctions) SearchType() string {
if len(s.app.history) > 0 && !s.app.history[s.app.historyIndex].Formatter.Searchable() {
return "none"
}
if s.app.config.General.ContextSpecificSearch {
return "response specific"
}
return "regex"
}
func (s *StatusLine) Update(v *gocui.View, a *App) {
v.Clear()
err := s.tpl.Execute(v, &StatusLineFunctions{app: a})
if err != nil {
fmt.Fprintf(v, "StatusLine update error: %v", err)
}
}
func (s *StatusLineFunctions) DisableRedirect() string {
if s.app.config.General.FollowRedirects {
return ""
}
return "Activated"
}
func NewStatusLine(format string) (*StatusLine, error) {
tpl, err := template.New("status line").Parse(format)
if err != nil {
return nil, err
}
return &StatusLine{
tpl: tpl,
}, nil
}
================================================
FILE: wuzz.go
================================================
package main
import (
"bytes"
"compress/gzip"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
"net/url"
"os"
"path"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"time"
"golang.org/x/net/proxy"
"github.com/asciimoo/wuzz/config"
"github.com/asciimoo/wuzz/formatter"
"github.com/alessio/shellescape"
"github.com/awesome-gocui/gocui"
"github.com/mattn/go-runewidth"
)
const VERSION = "0.5.0"
const TIMEOUT_DURATION = 5 // in seconds
const WINDOWS_OS = "windows"
const SEARCH_PROMPT = "search> "
const (
ALL_VIEWS = ""
URL_VIEW = "url"
URL_PARAMS_VIEW = "get"
REQUEST_METHOD_VIEW = "method"
REQUEST_DATA_VIEW = "data"
REQUEST_HEADERS_VIEW = "headers"
STATUSLINE_VIEW = "status-line"
SEARCH_VIEW = "search"
RESPONSE_HEADERS_VIEW = "response-headers"
RESPONSE_BODY_VIEW = "response-body"
SEARCH_PROMPT_VIEW = "prompt"
POPUP_VIEW = "popup_view"
AUTOCOMPLETE_VIEW = "autocomplete_view"
ERROR_VIEW = "error_view"
HISTORY_VIEW = "history"
SAVE_DIALOG_VIEW = "save-dialog"
SAVE_RESPONSE_DIALOG_VIEW = "save-response-dialog"
LOAD_REQUEST_DIALOG_VIEW = "load-request-dialog"
SAVE_REQUEST_FORMAT_DIALOG_VIEW = "save-request-format-dialog"
SAVE_REQUEST_DIALOG_VIEW = "save-request-dialog"
SAVE_RESULT_VIEW = "save-result"
METHOD_LIST_VIEW = "method-list"
HELP_VIEW = "help"
)
var VIEW_TITLES = map[string]string{
POPUP_VIEW: "Info",
ERROR_VIEW: "Error",
HISTORY_VIEW: "History",
SAVE_RESPONSE_DIALOG_VIEW: "Save Response (enter to submit, ctrl+q to cancel)",
LOAD_REQUEST_DIALOG_VIEW: "Load Request (enter to submit, ctrl+q to cancel)",
SAVE_REQUEST_DIALOG_VIEW: "Save Request (enter to submit, ctrl+q to cancel)",
SAVE_REQUEST_FORMAT_DIALOG_VIEW: "Choose export format",
SAVE_RESULT_VIEW: "Save Result (press enter to close)",
METHOD_LIST_VIEW: "Methods",
HELP_VIEW: "Help",
}
type position struct {
// value = prc * MAX + abs
pct float32
abs int
}
type viewPosition struct {
x0, y0, x1, y1 position
}
var VIEW_POSITIONS = map[string]viewPosition{
URL_VIEW: {
position{0.0, 0},
position{0.0, 0},
position{1.0, -2},
position{0.0, 3}},
URL_PARAMS_VIEW: {
position{0.0, 0},
position{0.0, 3},
position{0.3, 0},
position{0.25, 0}},
REQUEST_METHOD_VIEW: {
position{0.0, 0},
position{0.25, 0},
position{0.3, 0},
position{0.25, 2}},
REQUEST_DATA_VIEW: {
position{0.0, 0},
position{0.25, 2},
position{0.3, 0},
position{0.5, 1}},
REQUEST_HEADERS_VIEW: {
position{0.0, 0},
position{0.5, 1},
position{0.3, 0},
position{1.0, -3}},
RESPONSE_HEADERS_VIEW: {
position{0.3, 0},
position{0.0, 3},
position{1.0, -2},
position{0.25, 2}},
RESPONSE_BODY_VIEW: {
position{0.3, 0},
position{0.25, 2},
position{1.0, -2},
position{1.0, -3}},
STATUSLINE_VIEW: {
position{0.0, -1},
position{1.0, -4},
position{1.0, 0},
position{1.0, -1}},
SEARCH_VIEW: {
position{0.0, 7},
position{1.0, -3},
position{1.0, -1},
position{1.0, -1}},
ERROR_VIEW: {
position{0.0, 0},
position{0.0, 0},
position{1.0, -2},
position{1.0, -2}},
SEARCH_PROMPT_VIEW: {
position{0.0, -1},
position{1.0, -3},
position{0.0, 8},
position{1.0, -1}},
POPUP_VIEW: {
position{0.5, -9999}, // set before usage using len(msg)
position{0.5, -1},
position{0.5, -9999}, // set before usage using len(msg)
position{0.5, 1}},
AUTOCOMPLETE_VIEW: {
position{0, -9999},
position{0, -9999},
position{0, -9999},
position{0, -9999}},
}
type viewProperties struct {
title string
frame bool
editable bool
wrap bool
editor gocui.Editor
text string
}
var VIEW_PROPERTIES = map[string]viewProperties{
URL_VIEW: {
title: "URL - press F1 for help",
frame: true,
editable: true,
wrap: false,
editor: &singleLineEditor{&defaultEditor},
},
URL_PARAMS_VIEW: {
title: "URL params",
frame: true,
editable: true,
wrap: false,
editor: &defaultEditor,
},
REQUEST_METHOD_VIEW: {
title: "Method",
frame: true,
editable: true,
wrap: false,
editor: &singleLineEditor{&defaultEditor},
text: DEFAULT_METHOD,
},
REQUEST_DATA_VIEW: {
title: "Request data (POST/PUT/PATCH)",
frame: true,
editable: true,
wrap: false,
editor: &defaultEditor,
},
REQUEST_HEADERS_VIEW: {
title: "Request headers",
frame: true,
editable: true,
wrap: false,
editor: &AutocompleteEditor{&defaultEditor, func(str string) []string {
return completeFromSlice(str, REQUEST_HEADERS)
}, []string{}, false},
},
RESPONSE_HEADERS_VIEW: {
title: "Response headers",
frame: true,
editable: true,
wrap: true,
editor: nil, // should be set using a.getViewEditor(g)
},
RESPONSE_BODY_VIEW: {
title: "Response body",
frame: true,
editable: true,
wrap: true,
editor: nil, // should be set using a.getViewEditor(g)
},
SEARCH_VIEW: {
title: "",
frame: false,
editable: true,
wrap: false,
editor: &singleLineEditor{&SearchEditor{&defaultEditor}},
},
STATUSLINE_VIEW: {
title: "",
frame: false,
editable: false,
wrap: false,
editor: nil,
text: "",
},
SEARCH_PROMPT_VIEW: {
title: "",
frame: false,
editable: false,
wrap: false,
editor: nil,
text: SEARCH_PROMPT,
},
POPUP_VIEW: {
title: "Info",
frame: true,
editable: false,
wrap: false,
editor: nil,
},
AUTOCOMPLETE_VIEW: {
title: "",
frame: false,
editable: false,
wrap: false,
editor: nil,
},
}
var METHODS = []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
http.MethodPatch,
http.MethodOptions,
http.MethodTrace,
http.MethodConnect,
http.MethodHead,
}
var EXPORT_FORMATS = []struct {
name string
export func(r Request) []byte
}{
{
name: "JSON",
export: exportJSON,
},
{
name: "curl",
export: exportCurl,
},
}
const DEFAULT_METHOD = http.MethodGet
var DEFAULT_FORMATTER = &formatter.TextFormatter{}
var CLIENT = &http.Client{
Timeout: time.Duration(TIMEOUT_DURATION * time.Second),
}
var TRANSPORT = &http.Transport{
Proxy: http.ProxyFromEnvironment,
}
var VIEWS = []string{
URL_VIEW,
URL_PARAMS_VIEW,
REQUEST_METHOD_VIEW,
REQUEST_DATA_VIEW,
REQUEST_HEADERS_VIEW,
SEARCH_VIEW,
RESPONSE_HEADERS_VIEW,
RESPONSE_BODY_VIEW,
}
var TLS_VERSIONS = map[string]uint16{
"SSL3.0": tls.VersionSSL30,
"TLS1.0": tls.VersionTLS10,
"TLS1.1": tls.VersionTLS11,
"TLS1.2": tls.VersionTLS12,
}
var defaultEditor ViewEditor
const (
MIN_WIDTH = 60
MIN_HEIGHT = 20
)
type Request struct {
Url string
Method string
GetParams string
Data string
Headers string
ResponseHeaders string
RawResponseBody []byte
ContentType string
Duration time.Duration
Formatter formatter.ResponseFormatter
}
type App struct {
viewIndex int
historyIndex int
currentPopup string
history []*Request
config *config.Config
statusLine *StatusLine
}
type ViewEditor struct {
app *App
g *gocui.Gui
backTabEscape bool
origEditor gocui.Editor
}
type AutocompleteEditor struct {
wuzzEditor *ViewEditor
completions func(string) []string
currentCompletions []string
isAutocompleting bool
}
type SearchEditor struct {
wuzzEditor *ViewEditor
}
// The singleLineEditor removes multi lines capabilities
type singleLineEditor struct {
wuzzEditor gocui.Editor
}
func init() {
TRANSPORT.DisableCompression = true
CLIENT.Transport = TRANSPORT
}
// Editor funcs
func (e *ViewEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
// handle back-tab (\033[Z) sequence
if e.backTabEscape {
if ch == 'Z' {
e.app.PrevView(e.g, nil)
e.backTabEscape = false
return
} else {
e.origEditor.Edit(v, 0, '[', gocui.ModAlt)
}
}
if ch == '[' && mod == gocui.ModAlt {
e.backTabEscape = true
return
}
// disable infinite down scroll
if key == gocui.KeyArrowDown && mod == gocui.ModNone {
_, cY := v.Cursor()
_, err := v.Line(cY)
if err != nil {
return
}
}
e.origEditor.Edit(v, key, ch, mod)
}
var symbolPattern = regexp.MustCompile("[a-zA-Z0-9-]+$")
func getLastSymbol(str string) string {
return symbolPattern.FindString(str)
}
func completeFromSlice(str string, completions []string) []string {
completed := []string{}
if str == "" || strings.TrimRight(str, " \n") != str {
return completed
}
for _, completion := range completions {
if strings.HasPrefix(completion, str) && str != completion {
completed = append(completed, completion)
}
}
return completed
}
func (e *AutocompleteEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
if key != gocui.KeyEnter {
e.wuzzEditor.Edit(v, key, ch, mod)
}
cx, cy := v.Cursor()
line, err := v.Line(cy)
trimmedLine := line[:cx]
if err != nil {
e.wuzzEditor.Edit(v, key, ch, mod)
return
}
lastSymbol := getLastSymbol(trimmedLine)
if key == gocui.KeyEnter && e.isAutocompleting {
currentCompletion := e.currentCompletions[0]
shouldDelete := true
if len(e.currentCompletions) == 1 {
shouldDelete = false
}
if shouldDelete {
for range lastSymbol {
v.EditDelete(true)
}
}
for _, char := range currentCompletion {
v.EditWrite(char)
}
closeAutocomplete(e.wuzzEditor.g)
e.isAutocompleting = false
return
} else if key == gocui.KeyEnter {
e.wuzzEditor.Edit(v, key, ch, mod)
}
closeAutocomplete(e.wuzzEditor.g)
e.isAutocompleting = false
completions := e.completions(lastSymbol)
e.currentCompletions = completions
cx, cy = v.Cursor()
sx, _ := v.Size()
ox, oy, _, _, _ := e.wuzzEditor.g.ViewPosition(v.Name())
maxWidth := sx - cx
maxHeight := 10
if len(completions) > 0 {
comps := completions
x := ox + cx
y := oy + cy
if len(comps) == 1 {
comps[0] = comps[0][len(lastSymbol):]
} else {
y += 1
x -= len(lastSymbol)
maxWidth += len(lastSymbol)
}
showAutocomplete(comps, x, y, maxWidth, maxHeight, e.wuzzEditor.g)
e.isAutocompleting = true
}
}
func (e *SearchEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
e.wuzzEditor.Edit(v, key, ch, mod)
e.wuzzEditor.g.Update(func(g *gocui.Gui) error {
e.wuzzEditor.app.PrintBody(g)
return nil
})
}
// The singleLineEditor removes multi lines capabilities
func (e singleLineEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
switch {
case (ch != 0 || key == gocui.KeySpace) && mod == 0:
e.wuzzEditor.Edit(v, key, ch, mod)
// At the end of the line the default gcui editor adds a whitespace
// Force him to remove
ox, _ := v.Cursor()
if ox > 1 && ox >= len(v.Buffer())-2 {
v.EditDelete(false)
}
return
case key == gocui.KeyEnter:
return
case key == gocui.KeyArrowRight:
ox, _ := v.Cursor()
if ox >= len(v.Buffer())-1 {
return
}
case key == gocui.KeyHome || key == gocui.KeyArrowUp:
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
return
case key == gocui.KeyEnd || key == gocui.KeyArrowDown:
width, _ := v.Size()
lineWidth := len(v.Buffer()) - 1
if lineWidth > width {
v.SetOrigin(lineWidth-width, 0)
lineWidth = width - 1
}
v.SetCursor(lineWidth, 0)
return
}
e.wuzzEditor.Edit(v, key, ch, mod)
}
//
func (a *App) getResponseViewEditor(g *gocui.Gui) gocui.Editor {
return &ViewEditor{a, g, false, gocui.EditorFunc(func(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
return
})}
}
func (p position) getCoordinate(max int) int {
return int(p.pct*float32(max)) + p.abs
}
func setView(g *gocui.Gui, viewName string) (*gocui.View, error) {
maxX, maxY := g.Size()
position := VIEW_POSITIONS[viewName]
return g.SetView(viewName,
position.x0.getCoordinate(maxX+1),
position.y0.getCoordinate(maxY+1),
position.x1.getCoordinate(maxX+1),
position.y1.getCoordinate(maxY+1),
0)
}
func setViewProperties(v *gocui.View, name string) {
v.Title = VIEW_PROPERTIES[name].title
v.Frame = VIEW_PROPERTIES[name].frame
v.Editable = VIEW_PROPERTIES[name].editable
v.Wrap = VIEW_PROPERTIES[name].wrap
v.Editor = VIEW_PROPERTIES[name].editor
setViewTextAndCursor(v, VIEW_PROPERTIES[name].text)
}
func (a *App) Layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if maxX < MIN_WIDTH || maxY < MIN_HEIGHT {
if v, err := setView(g, ERROR_VIEW); err != nil {
if err != gocui.ErrUnknownView {
return err
}
setViewDefaults(v)
v.Title = VIEW_TITLES[ERROR_VIEW]
g.Cursor = false
fmt.Fprintln(v, "Terminal is too small")
}
return nil
}
if _, err := g.View(ERROR_VIEW); err == nil {
g.DeleteView(ERROR_VIEW)
g.Cursor = true
a.setView(g)
}
for _, name := range []string{RESPONSE_HEADERS_VIEW, RESPONSE_BODY_VIEW} {
vp := VIEW_PROPERTIES[name]
vp.editor = a.getResponseViewEditor(g)
VIEW_PROPERTIES[name] = vp
}
if a.config.General.DefaultURLScheme != "" && !strings.HasSuffix(a.config.General.DefaultURLScheme, "://") {
p := VIEW_PROPERTIES[URL_VIEW]
p.text = a.config.General.DefaultURLScheme + "://"
VIEW_PROPERTIES[URL_VIEW] = p
}
for _, name := range []string{
URL_VIEW,
URL_PARAMS_VIEW,
REQUEST_METHOD_VIEW,
REQUEST_DATA_VIEW,
REQUEST_HEADERS_VIEW,
RESPONSE_HEADERS_VIEW,
RESPONSE_BODY_VIEW,
STATUSLINE_VIEW,
SEARCH_PROMPT_VIEW,
SEARCH_VIEW,
} {
if v, err := setView(g, name); err != nil {
if err != gocui.ErrUnknownView {
return err
}
setViewProperties(v, name)
}
}
refreshStatusLine(a, g)
return nil
}
func (a *App) NextView(g *gocui.Gui, v *gocui.View) error {
a.viewIndex = (a.viewIndex + 1) % len(VIEWS)
return a.setView(g)
}
func (a *App) PrevView(g *gocui.Gui, v *gocui.View) error {
a.viewIndex = (a.viewIndex - 1 + len(VIEWS)) % len(VIEWS)
return a.setView(g)
}
func (a *App) setView(g *gocui.Gui) error {
a.closePopup(g, a.currentPopup)
_, err := g.SetCurrentView(VIEWS[a.viewIndex])
return err
}
func (a *App) setViewByName(g *gocui.Gui, name string) error {
for i, v := range VIEWS {
if v == name {
a.viewIndex = i
return a.setView(g)
}
}
return fmt.Errorf("View not found")
}
func popup(g *gocui.Gui, msg string) {
pos := VIEW_POSITIONS[POPUP_VIEW]
pos.x0.abs = -len(msg)/2 - 1
pos.x1.abs = len(msg)/2 + 1
VIEW_POSITIONS[POPUP_VIEW] = pos
p := VIEW_PROPERTIES[POPUP_VIEW]
p.text = msg
VIEW_PROPERTIES[POPUP_VIEW] = p
if v, err := setView(g, POPUP_VIEW); err != nil {
if err != gocui.ErrUnknownView {
return
}
setViewProperties(v, POPUP_VIEW)
g.SetViewOnTop(POPUP_VIEW)
}
}
func minInt(x, y int) int {
if x < y {
return x
}
return y
}
func closeAutocomplete(g *gocui.Gui) {
g.DeleteView(AUTOCOMPLETE_VIEW)
}
func showAutocomplete(completions []string, left, top, maxWidth, maxHeight int, g *gocui.Gui) {
// Get the width of the widest completion
completionsWidth := 0
for _, completion := range completions {
thisCompletionWidth := len(completion)
if thisCompletionWidth > completionsWidth {
completionsWidth = thisCompletionWidth
}
}
// Get the width and height of the autocomplete window
width := minInt(completionsWidth, maxWidth)
height := minInt(len(completions), maxHeight)
newPos := viewPosition{
x0: position{0, left},
y0: position{0, top},
x1: position{0, left + width + 1},
y1: position{0, top + height + 1},
}
VIEW_POSITIONS[AUTOCOMPLETE_VIEW] = newPos
p := VIEW_PROPERTIES[AUTOCOMPLETE_VIEW]
p.text = strings.Join(completions, "\n")
VIEW_PROPERTIES[AUTOCOMPLETE_VIEW] = p
if v, err := setView(g, AUTOCOMPLETE_VIEW); err != nil {
if err != gocui.ErrUnknownView {
return
}
setViewProperties(v, AUTOCOMPLETE_VIEW)
v.BgColor = gocui.ColorBlue
v.FgColor = gocui.ColorDefault
g.SetViewOnTop(AUTOCOMPLETE_VIEW)
}
}
func writeSortedHeaders(output io.Writer, h http.Header) {
hkeys := make([]string, 0, len(h))
for hname := range h {
hkeys = append(hkeys, hname)
}
sort.Strings(hkeys)
for _, hname := range hkeys {
fmt.Fprintf(output, "\x1b[0;33m%v:\x1b[0;0m %v\n", hname, strings.Join(h[hname], ","))
}
}
func (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
vrb.Clear()
vrh, _ := g.View(RESPONSE_HEADERS_VIEW)
vrh.Clear()
popup(g, "Sending request..")
var r *Request = &Request{}
go func(g *gocui.Gui, a *App, r *Request) error {
defer g.DeleteView(POPUP_VIEW)
// parse url
r.Url = getViewValue(g, URL_VIEW)
u, err := url.Parse(r.Url)
if err != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "URL parse error: %v", err)
return nil
})
return nil
}
q, err := url.ParseQuery(strings.Replace(getViewValue(g, URL_PARAMS_VIEW), "\n", "&", -1))
if err != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Invalid GET parameters: %v", err)
return nil
})
return nil
}
originalQuery := u.Query()
for k, v := range q {
for _, qp := range v {
originalQuery.Add(k, qp)
}
}
u.RawQuery = originalQuery.Encode()
r.GetParams = u.RawQuery
// parse method
r.Method = getViewValue(g, REQUEST_METHOD_VIEW)
// set headers
headers := http.Header{}
headers.Set("User-Agent", "")
r.Headers = getViewValue(g, REQUEST_HEADERS_VIEW)
for _, header := range strings.Split(r.Headers, "\n") {
if header != "" {
header_parts := strings.SplitN(header, ": ", 2)
if len(header_parts) != 2 {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Invalid header: %v", header)
return nil
})
return nil
}
headers.Set(header_parts[0], header_parts[1])
}
}
var body io.Reader
// parse POST/PUT/PATCH data
if r.Method == http.MethodPost || r.Method == http.MethodPut || r.Method == http.MethodPatch {
bodyStr := getViewValue(g, REQUEST_DATA_VIEW)
r.Data = bodyStr
if headers.Get("Content-Type") != "multipart/form-data" {
if headers.Get("Content-Type") == "application/x-www-form-urlencoded" {
bodyStr = strings.Replace(bodyStr, "\n", "&", -1)
}
body = bytes.NewBufferString(bodyStr)
} else {
var bodyBytes bytes.Buffer
multiWriter := multipart.NewWriter(&bodyBytes)
defer multiWriter.Close()
postData, err := url.ParseQuery(strings.Replace(getViewValue(g, REQUEST_DATA_VIEW), "\n", "&", -1))
if err != nil {
return err
}
for postKey, postValues := range postData {
for i := range postValues {
if len([]rune(postValues[i])) > 0 && postValues[i][0] == '@' {
file, err := os.Open(postValues[i][1:])
if err != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Error: %v", err)
return nil
})
return err
}
defer file.Close()
fw, err := multiWriter.CreateFormFile(postKey, path.Base(postValues[i][1:]))
if err != nil {
return err
}
if _, err := io.Copy(fw, file); err != nil {
return err
}
} else {
fw, err := multiWriter.CreateFormField(postKey)
if err != nil {
return err
}
if _, err := fw.Write([]byte(postValues[i])); err != nil {
return err
}
}
}
}
body = bytes.NewReader(bodyBytes.Bytes())
}
}
// create request
req, err := http.NewRequest(r.Method, u.String(), body)
if err != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Request error: %v", err)
return nil
})
return nil
}
req.Header = headers
// set the `Host` header
if headers.Get("Host") != "" {
req.Host = headers.Get("Host")
}
// do request
start := time.Now()
response, err := CLIENT.Do(req)
r.Duration = time.Since(start)
if err != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Response error: %v", err)
return nil
})
return nil
}
defer response.Body.Close()
// extract body
r.ContentType = response.Header.Get("Content-Type")
if response.Header.Get("Content-Encoding") == "gzip" {
reader, err := gzip.NewReader(response.Body)
if err == nil {
defer reader.Close()
response.Body = reader
} else {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
fmt.Fprintf(vrb, "Cannot uncompress response: %v", err)
return nil
})
return nil
}
}
bodyBytes, err := ioutil.ReadAll(response.Body)
if err == nil {
r.RawResponseBody = bodyBytes
}
r.Formatter = formatter.New(a.config, r.ContentType)
// add to history
a.history = append(a.history, r)
a.historyIndex = len(a.history) - 1
// render response
g.Update(func(g *gocui.Gui) error {
vrh, _ := g.View(RESPONSE_HEADERS_VIEW)
a.PrintBody(g)
// print status code
status_color := 32
if response.StatusCode != 200 {
status_color = 31
}
header := &strings.Builder{}
fmt.Fprintf(
header,
"\x1b[0;%dmHTTP/1.1 %v %v\x1b[0;0m\n",
status_color,
response.StatusCode,
http.StatusText(response.StatusCode),
)
writeSortedHeaders(header, response.Header)
// According to the Go documentation, the Trailer maps trailer
// keys to values in the same format as Header
writeSortedHeaders(header, response.Trailer)
r.ResponseHeaders = header.String()
fmt.Fprint(vrh, r.ResponseHeaders)
if _, err := vrh.Line(0); err != nil {
vrh.SetOrigin(0, 0)
}
return nil
})
return nil
}(g, a, r)
return nil
}
func (a *App) PrintBody(g *gocui.Gui) {
g.Update(func(g *gocui.Gui) error {
if len(a.history) == 0 {
return nil
}
req := a.history[a.historyIndex]
if req.RawResponseBody == nil {
return nil
}
vrb, _ := g.View(RESPONSE_BODY_VIEW)
vrb.Clear()
var responseFormatter formatter.ResponseFormatter
responseFormatter = req.Formatter
vrb.Title = VIEW_PROPERTIES[vrb.Name()].title + " " + responseFormatter.Title()
search_text := getViewValue(g, "search")
if search_text == "" || !responseFormatter.Searchable() {
err := responseFormatter.Format(vrb, req.RawResponseBody)
if err != nil {
fmt.Fprintf(vrb, "Error: cannot decode response body: %v", err)
return nil
}
if _, err := vrb.Line(0); !a.config.General.PreserveScrollPosition || err != nil {
vrb.SetOrigin(0, 0)
}
return nil
}
if !a.config.General.ContextSpecificSearch {
responseFormatter = DEFAULT_FORMATTER
}
vrb.SetOrigin(0, 0)
results, err := responseFormatter.Search(search_text, req.RawResponseBody)
if err != nil {
fmt.Fprint(vrb, "Search error: ", err)
return nil
}
if len(results) == 0 {
vrb.Title = "No results"
fmt.Fprint(vrb, "Error: no results")
return nil
}
vrb.Title = fmt.Sprintf("%d results", len(results))
for _, result := range results {
fmt.Fprintf(vrb, "-----\n%s\n", result)
}
return nil
})
}
func parseKey(k string) (interface{}, gocui.Modifier, error) {
mod := gocui.ModNone
if strings.Index(k, "Alt") == 0 {
mod = gocui.ModAlt
k = k[3:]
}
switch len(k) {
case 0:
return 0, 0, errors.New("Empty key string")
case 1:
if mod != gocui.ModNone {
k = strings.ToLower(k)
}
return rune(k[0]), mod, nil
}
key, found := KEYS[k]
if !found {
return 0, 0, fmt.Errorf("Unknown key: %v", k)
}
return key, mod, nil
}
func (a *App) setKey(g *gocui.Gui, keyStr, commandStr, viewName string) error {
if commandStr == "" {
return nil
}
key, mod, err := parseKey(keyStr)
if err != nil {
return err
}
commandParts := strings.SplitN(commandStr, " ", 2)
command := commandParts[0]
var commandArgs string
if len(commandParts) == 2 {
commandArgs = commandParts[1]
}
keyFnGen, found := COMMANDS[command]
if !found {
return fmt.Errorf("Unknown command: %v", command)
}
keyFn := keyFnGen(commandArgs, a)
if err := g.SetKeybinding(viewName, key, mod, keyFn); err != nil {
return fmt.Errorf("Failed to set key '%v': %v", keyStr, err)
}
return nil
}
func (a *App) printViewKeybindings(v io.Writer, viewName string) {
keys, found := a.config.Keys[viewName]
if !found {
return
}
mk := make([]string, len(keys))
i := 0
for k := range keys {
mk[i] = k
i++
}
sort.Strings(mk)
fmt.Fprintf(v, "\n %v\n", viewName)
for _, key := range mk {
fmt.Fprintf(v, " %-15v %v\n", key, keys[key])
}
}
func (a *App) SetKeys(g *gocui.Gui) error {
// load config keybindings
for viewName, keys := range a.config.Keys {
if viewName == "global" {
viewName = ALL_VIEWS
}
for keyStr, commandStr := range keys {
if err := a.setKey(g, keyStr, commandStr, viewName); err != nil {
return err
}
}
}
g.SetKeybinding(ALL_VIEWS, gocui.KeyF1, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
if a.currentPopup == HELP_VIEW {
a.closePopup(g, HELP_VIEW)
return nil
}
help, err := a.CreatePopupView(HELP_VIEW, 60, 40, g)
if err != nil {
return err
}
help.Title = VIEW_TITLES[HELP_VIEW]
help.Highlight = false
fmt.Fprint(help, "Keybindings:\n")
a.printViewKeybindings(help, "global")
for _, viewName := range VIEWS {
if _, found := a.config.Keys[viewName]; !found {
continue
}
a.printViewKeybindings(help, viewName)
}
g.SetViewOnTop(HELP_VIEW)
g.SetCurrentView(HELP_VIEW)
return nil
})
g.SetKeybinding(ALL_VIEWS, gocui.KeyF11, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
a.config.General.FollowRedirects = !a.config.General.FollowRedirects
refreshStatusLine(a, g)
return nil
})
g.SetKeybinding(ALL_VIEWS, gocui.KeyCtrlL, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
if a.currentPopup != "" {
return nil
}
a.restoreRequest(g, 0, true)
g.SetCurrentView(URL_VIEW)
return nil
})
g.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyEnter, gocui.ModNone, a.ToggleMethodList)
cursDown := func(g *gocui.Gui, v *gocui.View) error {
cx, cy := v.Cursor()
v.SetCursor(cx, cy+1)
return nil
}
cursUp := func(g *gocui.Gui, v *gocui.View) error {
cx, cy := v.Cursor()
if cy > 0 {
cy -= 1
}
v.SetCursor(cx, cy)
return nil
}
// history key bindings
g.SetKeybinding(HISTORY_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)
g.SetKeybinding(HISTORY_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)
g.SetKeybinding(HISTORY_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
_, cy := v.Cursor()
// TODO error
if len(a.history) <= cy {
return nil
}
a.restoreRequest(g, cy, false)
return nil
})
// method key bindings
g.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyArrowDown, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
value := strings.TrimSpace(v.Buffer())
for i, val := range METHODS {
if val == value && i != len(METHODS)-1 {
setViewTextAndCursor(v, METHODS[i+1])
}
}
return nil
})
g.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyArrowUp, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
value := strings.TrimSpace(v.Buffer())
for i, val := range METHODS {
if val == value && i != 0 {
setViewTextAndCursor(v, METHODS[i-1])
}
}
return nil
})
g.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)
g.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)
g.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
_, cy := v.Cursor()
v, _ = g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(v, METHODS[cy])
a.closePopup(g, METHOD_LIST_VIEW)
return nil
})
g.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)
g.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)
g.SetKeybinding(SAVE_DIALOG_VIEW, gocui.KeyCtrlQ, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
a.closePopup(g, SAVE_DIALOG_VIEW)
return nil
})
g.SetKeybinding(SAVE_RESULT_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
a.closePopup(g, SAVE_RESULT_VIEW)
return nil
})
return nil
}
func (a *App) closePopup(g *gocui.Gui, viewname string) {
_, err := g.View(viewname)
if err == nil {
a.currentPopup = ""
g.DeleteView(viewname)
g.SetCurrentView(VIEWS[a.viewIndex%len(VIEWS)])
g.Cursor = true
}
}
// CreatePopupView create a popup like view
func (a *App) CreatePopupView(name string, width, height int, g *gocui.Gui) (v *gocui.View, err error) {
// Remove any concurrent popup
a.closePopup(g, a.currentPopup)
g.Cursor = false
maxX, maxY := g.Size()
if height > maxY-4 {
height = maxY - 4
}
if width > maxX-4 {
width = maxX - 4
}
v, err = g.SetView(name, maxX/2-width/2-1, maxY/2-height/2-1, maxX/2+width/2, maxY/2+height/2+1, 0)
if err != nil && err != gocui.ErrUnknownView {
return
}
err = nil
v.Wrap = false
v.Frame = true
v.Highlight = true
v.SelFgColor = gocui.ColorYellow
v.SelBgColor = gocui.ColorDefault
a.currentPopup = name
return
}
func (a *App) LoadRequest(g *gocui.Gui, loadLocation string) (err error) {
requestJson, ioErr := ioutil.ReadFile(loadLocation)
if ioErr != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
vrb.Clear()
fmt.Fprintf(vrb, "File reading error: %v", ioErr)
return nil
})
return nil
}
var requestMap map[string]string
jsonErr := json.Unmarshal(requestJson, &requestMap)
if jsonErr != nil {
g.Update(func(g *gocui.Gui) error {
vrb, _ := g.View(RESPONSE_BODY_VIEW)
vrb.Clear()
fmt.Fprintf(vrb, "JSON decoding error: %v", jsonErr)
return nil
})
return nil
}
var v *gocui.View
url, exists := requestMap[URL_VIEW]
if exists {
v, _ = g.View(URL_VIEW)
setViewTextAndCursor(v, url)
}
method, exists := requestMap[REQUEST_METHOD_VIEW]
if exists {
v, _ = g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(v, method)
}
params, exists := requestMap[URL_PARAMS_VIEW]
if exists {
v, _ = g.View(URL_PARAMS_VIEW)
setViewTextAndCursor(v, params)
}
data, exists := requestMap[REQUEST_DATA_VIEW]
if exists {
g.Update(func(g *gocui.Gui) error {
v, _ = g.View(REQUEST_DATA_VIEW)
v.Clear()
fmt.Fprintf(v, "%v", data)
return nil
})
}
headers, exists := requestMap[REQUEST_HEADERS_VIEW]
if exists {
v, _ = g.View(REQUEST_HEADERS_VIEW)
setViewTextAndCursor(v, headers)
}
return nil
}
func (a *App) ToggleHistory(g *gocui.Gui, _ *gocui.View) (err error) {
// Destroy if present
if a.currentPopup == HISTORY_VIEW {
a.closePopup(g, HISTORY_VIEW)
return
}
history, err := a.CreatePopupView(HISTORY_VIEW, 100, len(a.history), g)
if err != nil {
return
}
history.Title = VIEW_TITLES[HISTORY_VIEW]
if len(a.history) == 0 {
setViewTextAndCursor(history, "[!] No items in history")
return
}
for i, r := range a.history {
req_str := fmt.Sprintf("[%02d] %v %v", i, r.Method, r.Url)
if r.GetParams != "" {
req_str += fmt.Sprintf("?%v", strings.Replace(r.GetParams, "\n", "&", -1))
}
if r.Data != "" {
req_str += fmt.Sprintf(" %v", strings.Replace(r.Data, "\n", "&", -1))
}
if r.Headers != "" {
req_str += fmt.Sprintf(" %v", strings.Replace(r.Headers, "\n", ";", -1))
}
fmt.Fprintln(history, req_str)
}
g.SetViewOnTop(HISTORY_VIEW)
g.SetCurrentView(HISTORY_VIEW)
history.SetCursor(0, a.historyIndex)
return
}
func (a *App) SaveRequest(g *gocui.Gui, _ *gocui.View) (err error) {
// Destroy if present
if a.currentPopup == SAVE_REQUEST_FORMAT_DIALOG_VIEW {
a.closePopup(g, SAVE_REQUEST_FORMAT_DIALOG_VIEW)
return
}
// Create the view listing the possible formats
popup, err := a.CreatePopupView(SAVE_REQUEST_FORMAT_DIALOG_VIEW, 30, len(EXPORT_FORMATS), g)
if err != nil {
return err
}
popup.Title = VIEW_TITLES[SAVE_REQUEST_FORMAT_DIALOG_VIEW]
// Populate the popup with the available formats
for _, r := range EXPORT_FORMATS {
fmt.Fprintln(popup, r.name)
}
g.SetViewOnTop(SAVE_REQUEST_FORMAT_DIALOG_VIEW)
g.SetCurrentView(SAVE_REQUEST_FORMAT_DIALOG_VIEW)
popup.SetCursor(0, 0)
// Bind the enter key, when the format is chosen, save the choice and open
// the save popup
g.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
// Save the format index
_, format := v.Cursor()
// Open the Save popup
return a.OpenSaveDialog(VIEW_TITLES[SAVE_REQUEST_DIALOG_VIEW], g,
func(g *gocui.Gui, _ *gocui.View) error {
defer a.closePopup(g, SAVE_DIALOG_VIEW)
saveLocation := getViewValue(g, SAVE_DIALOG_VIEW)
r := Request{
Url: getViewValue(g, URL_VIEW),
Method: getViewValue(g, REQUEST_METHOD_VIEW),
GetParams: getViewValue(g, URL_PARAMS_VIEW),
Data: getViewValue(g, REQUEST_DATA_VIEW),
Headers: getViewValue(g, REQUEST_HEADERS_VIEW),
}
// Export the request using the chosent format
request := EXPORT_FORMATS[format].export(r)
// Write the file
ioerr := ioutil.WriteFile(saveLocation, []byte(request), 0644)
saveResult := fmt.Sprintf("Request saved successfully in %s", EXPORT_FORMATS[format].name)
if ioerr != nil {
saveResult = "Error saving request: " + ioerr.Error()
}
viewErr := a.OpenSaveResultView(saveResult, g)
return viewErr
},
)
})
return
}
func (a *App) ToggleMethodList(g *gocui.Gui, _ *gocui.View) (err error) {
// Destroy if present
if a.currentPopup == METHOD_LIST_VIEW {
a.closePopup(g, METHOD_LIST_VIEW)
return
}
method, err := a.CreatePopupView(METHOD_LIST_VIEW, 50, len(METHODS), g)
if err != nil {
return
}
method.Title = VIEW_TITLES[METHOD_LIST_VIEW]
cur := getViewValue(g, REQUEST_METHOD_VIEW)
for i, r := range METHODS {
fmt.Fprintln(method, r)
if cur == r {
method.SetCursor(0, i)
}
}
g.SetViewOnTop(METHOD_LIST_VIEW)
g.SetCurrentView(METHOD_LIST_VIEW)
return
}
func (a *App) OpenSaveDialog(title string, g *gocui.Gui, save func(g *gocui.Gui, v *gocui.View) error) error {
dialog, err := a.CreatePopupView(SAVE_DIALOG_VIEW, 60, 1, g)
if err != nil {
return err
}
g.Cursor = true
dialog.Title = title
dialog.Editable = true
dialog.Wrap = false
currentDir, err := os.Getwd()
if err != nil {
currentDir = ""
}
currentDir += "/"
setViewTextAndCursor(dialog, currentDir)
g.SetViewOnTop(SAVE_DIALOG_VIEW)
g.SetCurrentView(SAVE_DIALOG_VIEW)
dialog.SetCursor(0, len(currentDir))
g.DeleteKeybinding(SAVE_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone)
g.SetKeybinding(SAVE_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone, save)
return nil
}
func (a *App) OpenSaveResultView(saveResult string, g *gocui.Gui) (err error) {
popupTitle := VIEW_TITLES[SAVE_RESULT_VIEW]
saveResHeight := 1
saveResWidth := len(saveResult) + 1
if len(popupTitle)+2 > saveResWidth {
saveResWidth = len(popupTitle) + 2
}
maxX, _ := g.Size()
if saveResWidth > maxX {
saveResHeight = saveResWidth/maxX + 1
saveResWidth = maxX
}
saveResultPopup, err := a.CreatePopupView(SAVE_RESULT_VIEW, saveResWidth, saveResHeight, g)
saveResultPopup.Title = popupTitle
setViewTextAndCursor(saveResultPopup, saveResult)
g.SetViewOnTop(SAVE_RESULT_VIEW)
g.SetCurrentView(SAVE_RESULT_VIEW)
return err
}
func (a *App) restoreRequest(g *gocui.Gui, idx int, isCleanToggle bool) {
if (idx < 0 || idx >= len(a.history)) && !isCleanToggle {
return
}
r := &Request{
Url: fmt.Sprintf("%s://", a.config.General.DefaultURLScheme),
Method: http.MethodGet,
}
if !isCleanToggle {
a.closePopup(g, HISTORY_VIEW)
a.historyIndex = idx
r = a.history[idx]
}
v, _ := g.View(URL_VIEW)
setViewTextAndCursor(v, r.Url)
v, _ = g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(v, r.Method)
v, _ = g.View(URL_PARAMS_VIEW)
setViewTextAndCursor(v, r.GetParams)
v, _ = g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(v, r.Data)
v, _ = g.View(REQUEST_HEADERS_VIEW)
setViewTextAndCursor(v, r.Headers)
v, _ = g.View(RESPONSE_HEADERS_VIEW)
setViewTextAndCursor(v, r.ResponseHeaders)
switch isCleanToggle {
case true:
v, _ = g.View(RESPONSE_BODY_VIEW)
setViewTextAndCursor(v, "")
default:
a.PrintBody(g)
}
}
func (a *App) LoadConfig(configPath string) error {
if configPath == "" {
// Load config from default path
configPath = config.GetDefaultConfigLocation()
}
// If the config file doesn't exist, load the default config
if _, err := os.Stat(configPath); os.IsNotExist(err) {
a.config = &config.DefaultConfig
a.config.Keys = config.DefaultKeys
a.statusLine, _ = NewStatusLine(a.config.General.StatusLine)
return nil
}
conf, err := config.LoadConfig(configPath)
if err != nil {
a.config = &config.DefaultConfig
a.config.Keys = config.DefaultKeys
return err
}
a.config = conf
sl, err := NewStatusLine(conf.General.StatusLine)
if err != nil {
a.config = &config.DefaultConfig
a.config.Keys = config.DefaultKeys
return err
}
a.statusLine = sl
return nil
}
func (a *App) ParseArgs(g *gocui.Gui, args []string) error {
a.Layout(g)
g.SetCurrentView(VIEWS[a.viewIndex])
vheader, err := g.View(REQUEST_HEADERS_VIEW)
if err != nil {
return errors.New("Too small screen")
}
vheader.Clear()
vget, _ := g.View(URL_PARAMS_VIEW)
vget.Clear()
content_type := ""
set_data := false
set_method := false
set_binary_data := false
arg_index := 1
args_len := len(args)
accept_types := make([]string, 0, 8)
var body_data []string
for arg_index < args_len {
arg := args[arg_index]
switch arg {
case "-H", "--header":
if arg_index == args_len-1 {
return errors.New("No header value specified")
}
arg_index += 1
header := args[arg_index]
fmt.Fprintf(vheader, "%v\n", header)
case "-d", "--data", "--data-binary", "--data-urlencode":
if arg_index == args_len-1 {
return errors.New("No POST/PUT/PATCH value specified")
}
arg_index += 1
set_data = true
set_binary_data = arg == "--data-binary"
arg_data := args[arg_index]
if !set_binary_data {
content_type = "form"
}
if arg == "--data-urlencode" {
// TODO: Replace with `url.PathEscape(..)` in Go 1.8
arg_data_url := &url.URL{Path: arg_data}
arg_data = arg_data_url.String()
}
body_data = append(body_data, arg_data)
case "-j", "--json":
if arg_index == args_len-1 {
return errors.New("No POST/PUT/PATCH value specified")
}
arg_index += 1
json_str := args[arg_index]
content_type = "json"
accept_types = append(accept_types, config.ContentTypes["json"])
set_data = true
vdata, _ := g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(vdata, json_str)
case "-X", "--request":
if arg_index == args_len-1 {
return errors.New("No HTTP method specified")
}
arg_index++
set_method = true
method := args[arg_index]
if content_type == "" && (method == http.MethodPost || method == http.MethodPut || method == http.MethodPatch) {
content_type = "form"
}
vmethod, _ := g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(vmethod, method)
case "-t", "--timeout":
if arg_index == args_len-1 {
return errors.New("No timeout value specified")
}
arg_index += 1
timeout, err := strconv.Atoi(args[arg_index])
if err != nil || timeout <= 0 {
return errors.New("Invalid timeout value")
}
a.config.General.Timeout = config.Duration{Duration: time.Duration(timeout) * time.Millisecond}
case "--compressed":
vh, _ := g.View(REQUEST_HEADERS_VIEW)
if !strings.Contains(getViewValue(g, REQUEST_HEADERS_VIEW), "Accept-Encoding") {
fmt.Fprintln(vh, "Accept-Encoding: gzip, deflate")
}
case "-e", "--editor":
if arg_index == args_len-1 {
return errors.New("No timeout value specified")
}
arg_index += 1
a.config.General.Editor = args[arg_index]
case "-k", "--insecure":
a.config.General.Insecure = true
case "-R", "--disable-redirects":
a.config.General.FollowRedirects = false
case "--tlsv1.0":
a.config.General.TLSVersionMin = tls.VersionTLS10
a.config.General.TLSVersionMax = tls.VersionTLS10
case "--tlsv1.1":
a.config.General.TLSVersionMin = tls.VersionTLS11
a.config.General.TLSVersionMax = tls.VersionTLS11
case "--tlsv1.2":
a.config.General.TLSVersionMin = tls.VersionTLS12
a.config.General.TLSVersionMax = tls.VersionTLS12
case "-1", "--tlsv1":
a.config.General.TLSVersionMin = tls.VersionTLS10
a.config.General.TLSVersionMax = tls.VersionTLS12
case "-T", "--tls":
if arg_index >= args_len-1 {
return errors.New("Missing TLS version range: MIN,MAX")
}
arg_index++
arg := args[arg_index]
v := strings.Split(arg, ",")
min := v[0]
max := min
if len(v) > 1 {
max = v[1]
}
minV, minFound := TLS_VERSIONS[min]
if !minFound {
return errors.New("Minimum TLS version not found: " + min)
}
maxV, maxFound := TLS_VERSIONS[max]
if !maxFound {
return errors.New("Maximum TLS version not found: " + max)
}
a.config.General.TLSVersionMin = minV
a.config.General.TLSVersionMax = maxV
case "-x", "--proxy":
if arg_index == args_len-1 {
return errors.New("Missing proxy URL")
}
arg_index += 1
u, err := url.Parse(args[arg_index])
if err != nil {
return fmt.Errorf("Invalid proxy URL: %v", err)
}
switch u.Scheme {
case "", "http", "https":
TRANSPORT.Proxy = http.ProxyURL(u)
case "socks", "socks5":
dialer, err := proxy.SOCKS5("tcp", u.Host, nil, proxy.Direct)
if err != nil {
return fmt.Errorf("Can't connect to proxy: %v", err)
}
TRANSPORT.Dial = dialer.Dial
default:
return errors.New("Unknown proxy protocol")
}
case "-F", "--form":
if arg_index == args_len-1 {
return errors.New("No POST/PUT/PATCH value specified")
}
arg_index += 1
form_str := args[arg_index]
content_type = "multipart"
set_data = true
vdata, _ := g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(vdata, form_str)
case "-f", "--file":
if arg_index == args_len-1 {
return errors.New("-f or --file requires a file path be provided as an argument")
}
arg_index += 1
loadLocation := args[arg_index]
a.LoadRequest(g, loadLocation)
default:
u := args[arg_index]
if strings.Index(u, "http://") != 0 && strings.Index(u, "https://") != 0 {
u = fmt.Sprintf("%v://%v", a.config.General.DefaultURLScheme, u)
}
parsed_url, err := url.Parse(u)
if err != nil || parsed_url.Host == "" {
return errors.New("Invalid url")
}
if parsed_url.Path == "" {
parsed_url.Path = "/"
}
vurl, _ := g.View(URL_VIEW)
vurl.Clear()
for k, v := range parsed_url.Query() {
for _, vv := range v {
fmt.Fprintf(vget, "%v=%v\n", k, vv)
}
}
parsed_url.RawQuery = ""
setViewTextAndCursor(vurl, parsed_url.String())
}
arg_index += 1
}
if set_data && !set_method {
vmethod, _ := g.View(REQUEST_METHOD_VIEW)
setViewTextAndCursor(vmethod, http.MethodPost)
}
if !set_binary_data && content_type != "" && !a.hasHeader(g, "Content-Type") {
fmt.Fprintf(vheader, "Content-Type: %v\n", config.ContentTypes[content_type])
}
if len(accept_types) > 0 && !a.hasHeader(g, "Accept") {
fmt.Fprintf(vheader, "Accept: %v\n", strings.Join(accept_types, ","))
}
var merged_body_data string
if set_data && !set_binary_data {
merged_body_data = strings.Join(body_data, "&")
}
vdata, _ := g.View(REQUEST_DATA_VIEW)
setViewTextAndCursor(vdata, merged_body_data)
return nil
}
func (a *App) hasHeader(g *gocui.Gui, h string) bool {
for _, header := range strings.Split(getViewValue(g, REQUEST_HEADERS_VIEW), "\n") {
if header == "" {
continue
}
header_parts := strings.SplitN(header, ": ", 2)
if len(header_parts) != 2 {
continue
}
if header_parts[0] == h {
return true
}
}
return false
}
// Apply startup config values. This is run after a.ParseArgs, so that
// args can override the provided config values
func (a *App) InitConfig() {
CLIENT.Timeout = a.config.General.Timeout.Duration
TRANSPORT.TLSClientConfig = &tls.Config{
InsecureSkipVerify: a.config.General.Insecure,
MinVersion: a.config.General.TLSVersionMin,
MaxVersion: a.config.General.TLSVersionMax,
}
CLIENT.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
if a.config.General.FollowRedirects {
return nil
}
return http.ErrUseLastResponse
}
}
func refreshStatusLine(a *App, g *gocui.Gui) {
sv, _ := g.View(STATUSLINE_VIEW)
sv.BgColor = gocui.ColorDefault | gocui.AttrReverse
sv.FgColor = gocui.ColorDefault | gocui.AttrReverse
a.statusLine.Update(sv, a)
}
func initApp(a *App, g *gocui.Gui) {
g.Cursor = true
g.InputEsc = false
g.BgColor = gocui.ColorDefault
g.FgColor = gocui.ColorDefault
g.SetManagerFunc(a.Layout)
}
func getViewValue(g *gocui.Gui, name string) string {
v, err := g.View(name)
if err != nil {
return ""
}
return strings.TrimSpace(v.Buffer())
}
func setViewDefaults(v *gocui.View) {
v.Frame = true
v.Wrap = false
}
func setViewTextAndCursor(v *gocui.View, s string) {
v.Clear()
fmt.Fprint(v, s)
v.SetCursor(len(s), 0)
}
func help() {
fmt.Println(`wuzz - Interactive cli tool for HTTP inspection
Usage: wuzz [-H|--header HEADER]... [-d|--data|--data-binary DATA] [-X|--request METHOD] [-t|--timeout MSECS] [URL]
Other command line options:
-c, --config PATH Specify custom configuration file
-e, --editor EDITOR Specify external editor command
-f, --file REQUEST Load a previous request
-F, --form DATA Add multipart form request data and set related request headers
If the value starts with @ it will be handled as a file path for upload
-h, --help Show this
-j, --json JSON Add JSON request data and set related request headers
-k, --insecure Allow insecure SSL certs
-R, --disable-redirects Do not follow HTTP redirects
-T, --tls MIN,MAX Restrict allowed TLS versions (values: SSL3.0,TLS1.0,TLS1.1,TLS1.2)
Examples: wuzz -T TLS1.1 (TLS1.1 only)
wuzz -T TLS1.0,TLS1.1 (from TLS1.0 up to TLS1.1)
--tlsv1.0 Forces TLS1.0 only
--tlsv1.1 Forces TLS1.1 only
--tlsv1.2 Forces TLS1.2 only
-1, --tlsv1 Forces TLS version 1.x (1.0, 1.1 or 1.2)
-v, --version Display version number
-x, --proxy URL Set HTTP(S) or SOCKS5 proxy
Key bindings:
ctrl+r Send request
ctrl+s Save response
ctrl+e Save request
ctrl+f Load request
tab, ctrl+j Next window
shift+tab, ctrl+k Previous window
alt+h Show history
pageUp Scroll up the current window
pageDown Scroll down the current window`,
)
}
func main() {
configPath := ""
args := os.Args
for i, arg := range os.Args {
switch arg {
case "-h", "--help":
help()
return
case "-v", "--version":
fmt.Printf("wuzz %v\n", VERSION)
return
case "-c", "--config":
configPath = os.Args[i+1]
args = append(os.Args[:i], os.Args[i+2:]...)
if _, err := os.Stat(configPath); os.IsNotExist(err) {
log.Fatal("Config file specified but does not exist: \"" + configPath + "\"")
}
}
}
var g *gocui.Gui
var err error
for _, outputMode := range []gocui.OutputMode{gocui.Output256, gocui.OutputNormal} {
g, err = gocui.NewGui(outputMode, true)
if err == nil {
break
}
}
if err != nil {
log.Panicln(err)
}
if runtime.GOOS == WINDOWS_OS && runewidth.IsEastAsian() {
g.ASCII = true
}
app := &App{history: make([]*Request, 0, 31)}
// overwrite default editor
defaultEditor = ViewEditor{app, g, false, gocui.DefaultEditor}
initApp(app, g)
// load config (must be done *before* app.ParseArgs, as arguments
// should be able to override config values). An empty string passed
// to LoadConfig results in LoadConfig loading the default config
// location. If there is no config, the values in
// config.DefaultConfig will be used.
err = app.LoadConfig(configPath)
if err != nil {
g.Close()
log.Fatalf("Error loading config file: %v", err)
}
err = app.ParseArgs(g, args)
// Some of the values in the config need to have some startup
// behavior associated with them. This is run after ParseArgs so
// that command-line arguments can override configuration values.
app.InitConfig()
if err != nil {
g.Close()
fmt.Println("Error!", err)
os.Exit(1)
}
err = app.SetKeys(g)
if err != nil {
g.Close()
fmt.Println("Error!", err)
os.Exit(1)
}
defer g.Close()
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}
}
func exportJSON(r Request) []byte {
requestMap := map[string]string{
URL_VIEW: r.Url,
REQUEST_METHOD_VIEW: r.Method,
URL_PARAMS_VIEW: r.GetParams,
REQUEST_DATA_VIEW: r.Data,
REQUEST_HEADERS_VIEW: r.Headers,
}
request, err := json.Marshal(requestMap)
if err != nil {
return []byte{}
}
return request
}
func exportCurl(r Request) []byte {
var headers, params string
for _, header := range strings.Split(r.Headers, "\n") {
if header == "" {
continue
}
headers = fmt.Sprintf("%s -H %s", headers, shellescape.Quote(header))
}
if r.GetParams != "" {
params = fmt.Sprintf("?%s", r.GetParams)
}
return []byte(fmt.Sprintf("curl %s -X %s -d %s %s\n", headers, r.Method, shellescape.Quote(r.Data), shellescape.Quote(r.Url+params)))
}
gitextract_9scu9mfj/ ├── .dockerignore ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── _config.yml ├── commands.go ├── config/ │ └── config.go ├── docker-entrypoint.sh ├── formatter/ │ ├── binary.go │ ├── formatter.go │ ├── formatter_test.go │ ├── html.go │ ├── json.go │ └── text.go ├── go.mod ├── go.sum ├── keys.go ├── request-headers.go ├── sample-config.toml ├── status-line.go └── wuzz.go
SYMBOL INDEX (140 symbols across 10 files)
FILE: commands.go
type CommandFunc (line 14) | type CommandFunc
function scrollView (line 134) | func scrollView(v *gocui.View, dy int) error {
function scrollViewUp (line 147) | func scrollViewUp(_ *gocui.Gui, v *gocui.View) error {
function scrollViewDown (line 151) | func scrollViewDown(_ *gocui.Gui, v *gocui.View) error {
function pageUp (line 155) | func pageUp(_ *gocui.Gui, v *gocui.View) error {
function pageDown (line 161) | func pageDown(_ *gocui.Gui, v *gocui.View) error {
function deleteLine (line 167) | func deleteLine(_ *gocui.Gui, v *gocui.View) error {
function deleteWord (line 188) | func deleteWord(_ *gocui.Gui, v *gocui.View) error {
function getCharCategory (line 213) | func getCharCategory(chr rune) int {
function quit (line 227) | func quit(g *gocui.Gui, v *gocui.View) error {
function openEditor (line 231) | func openEditor(g *gocui.Gui, v *gocui.View, editor string) error {
FILE: config/config.go
type Duration (line 22) | type Duration struct
method UnmarshalText (line 26) | func (d *Duration) UnmarshalText(text []byte) error {
type Config (line 32) | type Config struct
type GeneralOptions (line 37) | type GeneralOptions struct
function init (line 118) | func init() {
function LoadConfig (line 124) | func LoadConfig(configFile string) (*Config, error) {
function GetDefaultConfigLocation (line 157) | func GetDefaultConfigLocation() string {
FILE: formatter/binary.go
type binaryFormatter (line 10) | type binaryFormatter struct
method Format (line 13) | func (f *binaryFormatter) Format(writer io.Writer, data []byte) error {
method Title (line 18) | func (f *binaryFormatter) Title() string {
method Searchable (line 22) | func (f *binaryFormatter) Searchable() bool {
method Search (line 26) | func (f *binaryFormatter) Search(q string, body []byte) ([]string, err...
FILE: formatter/formatter.go
type ResponseFormatter (line 11) | type ResponseFormatter interface
function New (line 18) | func New(appConfig *config.Config, contentType string) ResponseFormatter {
FILE: formatter/formatter_test.go
function TestFormat (line 12) | func TestFormat(t *testing.T) {
function TestTitle (line 54) | func TestTitle(t *testing.T) {
function TestSearchable (line 80) | func TestSearchable(t *testing.T) {
function configFixture (line 98) | func configFixture(jsonEnabled bool) *config.Config {
FILE: formatter/html.go
type htmlFormatter (line 12) | type htmlFormatter struct
method Format (line 17) | func (f *htmlFormatter) Format(writer io.Writer, data []byte) error {
method Title (line 30) | func (f *htmlFormatter) Title() string {
method Search (line 34) | func (f *htmlFormatter) Search(q string, body []byte) ([]string, error) {
FILE: formatter/json.go
type jsonFormatter (line 12) | type jsonFormatter struct
method Format (line 17) | func (f *jsonFormatter) Format(writer io.Writer, data []byte) error {
method Title (line 29) | func (f *jsonFormatter) Title() string {
method Search (line 33) | func (f *jsonFormatter) Search(q string, body []byte) ([]string, error) {
FILE: formatter/text.go
type TextFormatter (line 8) | type TextFormatter struct
method Format (line 11) | func (f *TextFormatter) Format(writer io.Writer, data []byte) error {
method Title (line 16) | func (f *TextFormatter) Title() string {
method Searchable (line 20) | func (f *TextFormatter) Searchable() bool {
method Search (line 24) | func (f *TextFormatter) Search(q string, body []byte) ([]string, error) {
FILE: status-line.go
type StatusLine (line 11) | type StatusLine struct
method Update (line 52) | func (s *StatusLine) Update(v *gocui.View, a *App) {
type StatusLineFunctions (line 15) | type StatusLineFunctions struct
method Version (line 19) | func (_ *StatusLineFunctions) Version() string {
method Duration (line 23) | func (s *StatusLineFunctions) Duration() string {
method HistorySize (line 30) | func (s *StatusLineFunctions) HistorySize() string {
method RequestNumber (line 34) | func (s *StatusLineFunctions) RequestNumber() string {
method SearchType (line 42) | func (s *StatusLineFunctions) SearchType() string {
method DisableRedirect (line 60) | func (s *StatusLineFunctions) DisableRedirect() string {
function NewStatusLine (line 67) | func NewStatusLine(format string) (*StatusLine, error) {
FILE: wuzz.go
constant VERSION (line 35) | VERSION = "0.5.0"
constant TIMEOUT_DURATION (line 37) | TIMEOUT_DURATION = 5
constant WINDOWS_OS (line 38) | WINDOWS_OS = "windows"
constant SEARCH_PROMPT (line 39) | SEARCH_PROMPT = "search> "
constant ALL_VIEWS (line 42) | ALL_VIEWS = ""
constant URL_VIEW (line 44) | URL_VIEW = "url"
constant URL_PARAMS_VIEW (line 45) | URL_PARAMS_VIEW = "get"
constant REQUEST_METHOD_VIEW (line 46) | REQUEST_METHOD_VIEW = "method"
constant REQUEST_DATA_VIEW (line 47) | REQUEST_DATA_VIEW = "data"
constant REQUEST_HEADERS_VIEW (line 48) | REQUEST_HEADERS_VIEW = "headers"
constant STATUSLINE_VIEW (line 49) | STATUSLINE_VIEW = "status-line"
constant SEARCH_VIEW (line 50) | SEARCH_VIEW = "search"
constant RESPONSE_HEADERS_VIEW (line 51) | RESPONSE_HEADERS_VIEW = "response-headers"
constant RESPONSE_BODY_VIEW (line 52) | RESPONSE_BODY_VIEW = "response-body"
constant SEARCH_PROMPT_VIEW (line 54) | SEARCH_PROMPT_VIEW = "prompt"
constant POPUP_VIEW (line 55) | POPUP_VIEW = "popup_view"
constant AUTOCOMPLETE_VIEW (line 56) | AUTOCOMPLETE_VIEW = "autocomplete_view"
constant ERROR_VIEW (line 57) | ERROR_VIEW = "error_view"
constant HISTORY_VIEW (line 58) | HISTORY_VIEW = "history"
constant SAVE_DIALOG_VIEW (line 59) | SAVE_DIALOG_VIEW = "save-dialog"
constant SAVE_RESPONSE_DIALOG_VIEW (line 60) | SAVE_RESPONSE_DIALOG_VIEW = "save-response-dialog"
constant LOAD_REQUEST_DIALOG_VIEW (line 61) | LOAD_REQUEST_DIALOG_VIEW = "load-request-dialog"
constant SAVE_REQUEST_FORMAT_DIALOG_VIEW (line 62) | SAVE_REQUEST_FORMAT_DIALOG_VIEW = "save-request-format-dialog"
constant SAVE_REQUEST_DIALOG_VIEW (line 63) | SAVE_REQUEST_DIALOG_VIEW = "save-request-dialog"
constant SAVE_RESULT_VIEW (line 64) | SAVE_RESULT_VIEW = "save-result"
constant METHOD_LIST_VIEW (line 65) | METHOD_LIST_VIEW = "method-list"
constant HELP_VIEW (line 66) | HELP_VIEW = "help"
type position (line 82) | type position struct
method getCoordinate (line 540) | func (p position) getCoordinate(max int) int {
type viewPosition (line 88) | type viewPosition struct
type viewProperties (line 160) | type viewProperties struct
constant DEFAULT_METHOD (line 287) | DEFAULT_METHOD = http.MethodGet
constant MIN_WIDTH (line 319) | MIN_WIDTH = 60
constant MIN_HEIGHT (line 320) | MIN_HEIGHT = 20
type Request (line 323) | type Request struct
type App (line 336) | type App struct
method getResponseViewEditor (line 534) | func (a *App) getResponseViewEditor(g *gocui.Gui) gocui.Editor {
method Layout (line 564) | func (a *App) Layout(g *gocui.Gui) error {
method NextView (line 621) | func (a *App) NextView(g *gocui.Gui, v *gocui.View) error {
method PrevView (line 626) | func (a *App) PrevView(g *gocui.Gui, v *gocui.View) error {
method setView (line 631) | func (a *App) setView(g *gocui.Gui) error {
method setViewByName (line 637) | func (a *App) setViewByName(g *gocui.Gui, name string) error {
method SubmitRequest (line 728) | func (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error {
method PrintBody (line 945) | func (a *App) PrintBody(g *gocui.Gui) {
method setKey (line 1019) | func (a *App) setKey(g *gocui.Gui, keyStr, commandStr, viewName string...
method printViewKeybindings (line 1044) | func (a *App) printViewKeybindings(v io.Writer, viewName string) {
method SetKeys (line 1062) | func (a *App) SetKeys(g *gocui.Gui) error {
method closePopup (line 1188) | func (a *App) closePopup(g *gocui.Gui, viewname string) {
method CreatePopupView (line 1199) | func (a *App) CreatePopupView(name string, width, height int, g *gocui...
method LoadRequest (line 1225) | func (a *App) LoadRequest(g *gocui.Gui, loadLocation string) (err erro...
method ToggleHistory (line 1286) | func (a *App) ToggleHistory(g *gocui.Gui, _ *gocui.View) (err error) {
method SaveRequest (line 1323) | func (a *App) SaveRequest(g *gocui.Gui, _ *gocui.View) (err error) {
method ToggleMethodList (line 1385) | func (a *App) ToggleMethodList(g *gocui.Gui, _ *gocui.View) (err error) {
method OpenSaveDialog (line 1411) | func (a *App) OpenSaveDialog(title string, g *gocui.Gui, save func(g *...
method OpenSaveResultView (line 1438) | func (a *App) OpenSaveResultView(saveResult string, g *gocui.Gui) (err...
method restoreRequest (line 1459) | func (a *App) restoreRequest(g *gocui.Gui, idx int, isCleanToggle bool) {
method LoadConfig (line 1500) | func (a *App) LoadConfig(configPath string) error {
method ParseArgs (line 1532) | func (a *App) ParseArgs(g *gocui.Gui, args []string) error {
method hasHeader (line 1752) | func (a *App) hasHeader(g *gocui.Gui, h string) bool {
method InitConfig (line 1770) | func (a *App) InitConfig() {
type ViewEditor (line 345) | type ViewEditor struct
method Edit (line 375) | func (e *ViewEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod g...
type AutocompleteEditor (line 352) | type AutocompleteEditor struct
method Edit (line 422) | func (e *AutocompleteEditor) Edit(v *gocui.View, key gocui.Key, ch run...
type SearchEditor (line 359) | type SearchEditor struct
method Edit (line 488) | func (e *SearchEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod...
type singleLineEditor (line 364) | type singleLineEditor struct
method Edit (line 497) | func (e singleLineEditor) Edit(v *gocui.View, key gocui.Key, ch rune, ...
function init (line 368) | func init() {
function getLastSymbol (line 405) | func getLastSymbol(str string) string {
function completeFromSlice (line 409) | func completeFromSlice(str string, completions []string) []string {
function setView (line 544) | func setView(g *gocui.Gui, viewName string) (*gocui.View, error) {
function setViewProperties (line 555) | func setViewProperties(v *gocui.View, name string) {
function popup (line 647) | func popup(g *gocui.Gui, msg string) {
function minInt (line 666) | func minInt(x, y int) int {
function closeAutocomplete (line 673) | func closeAutocomplete(g *gocui.Gui) {
function showAutocomplete (line 677) | func showAutocomplete(completions []string, left, top, maxWidth, maxHeig...
function writeSortedHeaders (line 715) | func writeSortedHeaders(output io.Writer, h http.Header) {
function parseKey (line 996) | func parseKey(k string) (interface{}, gocui.Modifier, error) {
function refreshStatusLine (line 1785) | func refreshStatusLine(a *App, g *gocui.Gui) {
function initApp (line 1792) | func initApp(a *App, g *gocui.Gui) {
function getViewValue (line 1800) | func getViewValue(g *gocui.Gui, name string) string {
function setViewDefaults (line 1808) | func setViewDefaults(v *gocui.View) {
function setViewTextAndCursor (line 1813) | func setViewTextAndCursor(v *gocui.View, s string) {
function help (line 1819) | func help() {
function main (line 1857) | func main() {
function exportJSON (line 1938) | func exportJSON(r Request) []byte {
function exportCurl (line 1954) | func exportCurl(r Request) []byte {
Condensed preview — 24 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (144K chars).
[
{
"path": ".dockerignore",
"chars": 78,
"preview": "**\n\n!config\n!formatter\n!*.go\n!go.mod\n!sample-config.toml\n!docker-entrypoint.sh"
},
{
"path": ".gitignore",
"chars": 5,
"preview": "wuzz\n"
},
{
"path": ".travis.yml",
"chars": 746,
"preview": "language: go\ngo:\n - 1.12.x #Update go version\n - tip\nos:\n - linux\n # remove osx, getting vm from travis is extremely"
},
{
"path": "CHANGELOG.md",
"chars": 1358,
"preview": "## 0.5.0 2020.01.19\n\n - Added context specific search for HTML (goquery)\n - Request data displayed in request history\n -"
},
{
"path": "Dockerfile",
"chars": 561,
"preview": "FROM alpine:3.12 AS permissions-giver\n\n# Make sure docker-entrypoint.sh is executable, regardless of the build host.\nWOR"
},
{
"path": "LICENSE",
"chars": 34520,
"preview": " GNU AFFERO GENERAL PUBLIC LICENSE\n Version 3, 19 November 2007\n\n Copyright (C)"
},
{
"path": "README.md",
"chars": 3371,
"preview": "# wuzz\n\nInteractive cli tool for HTTP inspection.\n\nWuzz command line arguments are similar to cURL's arguments,\nso it ca"
},
{
"path": "_config.yml",
"chars": 26,
"preview": "theme: jekyll-theme-cayman"
},
{
"path": "commands.go",
"chars": 6524,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"unicode\"\n\n\t\"github.com/awesome-gocui/gocui\"\n)\n\n"
},
{
"path": "config/config.go",
"chars": 4203,
"preview": "package config\n\nimport (\n\t\"errors\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"time\"\n\n\t\"github.com/BurntSushi/toml\"\n\t\"github.com"
},
{
"path": "docker-entrypoint.sh",
"chars": 128,
"preview": "#!/bin/sh\nset -e\n\nif [ \"${1#-}\" != \"${1}\" ] || [ -z \"$(command -v \"${1}\")\" ]; then\n sleep 0.01\n set -- wuzz \"$@\"\nfi\n\ne"
},
{
"path": "formatter/binary.go",
"chars": 504,
"preview": "package formatter\n\nimport (\n\t\"encoding/hex\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n)\n\ntype binaryFormatter struct {\n}\n\nfunc (f *binaryFo"
},
{
"path": "formatter/formatter.go",
"chars": 788,
"preview": "package formatter\n\nimport (\n\t\"io\"\n\t\"mime\"\n\t\"strings\"\n\n\t\"github.com/asciimoo/wuzz/config\"\n)\n\ntype ResponseFormatter inter"
},
{
"path": "formatter/formatter_test.go",
"chars": 3340,
"preview": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"testing\"\n\n\t\"github.com/asciimoo/wuzz/config\"\n\t\"github.com/nwidger/jsoncolor\"\n\t\"gi"
},
{
"path": "formatter/html.go",
"chars": 1113,
"preview": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n\n\t\"github.com/PuerkitoBio/goquery\"\n\t\"github.com/x86kernel/htmlcolor"
},
{
"path": "formatter/json.go",
"chars": 1317,
"preview": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n\n\t\"github.com/nwidger/jsoncolor\"\n\t\"github.com/tidwall/gjson\"\n)\n\ntyp"
},
{
"path": "formatter/text.go",
"chars": 605,
"preview": "package formatter\n\nimport (\n\t\"io\"\n\t\"regexp\"\n)\n\ntype TextFormatter struct {\n}\n\nfunc (f *TextFormatter) Format(writer io.W"
},
{
"path": "go.mod",
"chars": 1871,
"preview": "module github.com/asciimoo/wuzz\n\ngo 1.24.0\n\ntoolchain go1.24.7\n\nrequire (\n\tgithub.com/BurntSushi/toml v1.5.0\n\tgithub.com"
},
{
"path": "go.sum",
"chars": 17132,
"preview": "github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\ngithub.com/BurntSushi/toml v0.3.1/go.m"
},
{
"path": "keys.go",
"chars": 2506,
"preview": "package main\n\nimport (\n\t\"github.com/awesome-gocui/gocui\"\n)\n\nvar KEYS = map[string]gocui.Key{\n\t\"F1\": gocui.Ke"
},
{
"path": "request-headers.go",
"chars": 533,
"preview": "package main\n\nvar REQUEST_HEADERS = []string{\n\t\"Accept\",\n\t\"Accept-Charset\",\n\t\"Accept-Encoding\",\n\t\"Accept-Language\",\n\t\"Ac"
},
{
"path": "sample-config.toml",
"chars": 1089,
"preview": "[general]\ntimeout = \"1m\"\nformatJSON = true\ninsecure = false\npreserveScrollPosition = true\nfollowRedirects = true\ndefault"
},
{
"path": "status-line.go",
"chars": 1453,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"text/template\"\n\n\t\"github.com/awesome-gocui/gocui\"\n)\n\ntype StatusLine struct {"
},
{
"path": "wuzz.go",
"chars": 49834,
"preview": "package main\n\nimport (\n\t\"bytes\"\n\t\"compress/gzip\"\n\t\"crypto/tls\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"lo"
}
]
About this extraction
This page contains the full source code of the asciimoo/wuzz GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 24 files (130.5 KB), approximately 41.9k tokens, and a symbol index with 140 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.