Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ae69b78
updated go mod;
Jul 9, 2022
de6fdcd
refs #11: make http2 settings configureable and orderable;
Apr 21, 2022
26d2bc4
fixed test;
Apr 22, 2022
99257bd
reimplemented response body decompression;
May 24, 2022
75232e8
configure pseudo header order on transport;
Jul 9, 2022
e11869d
make ConnectionFlow configurable and prepare for custom tls client;
Jul 11, 2022
6ceccbb
added http2 priority frames;
bogdanfinn Jul 12, 2022
41806f1
changed module name and bumdped version;
bogdanfinn Jul 20, 2022
e03ecd1
updated dependencies;
bogdanfinn Aug 7, 2022
9830698
updated dependencies;
bogdanfinn Aug 12, 2022
fa94cbb
updated dependencies;
bogdanfinn Aug 20, 2022
c2099ba
removed debug message;
bogdanfinn Aug 23, 2022
f1be6a6
added constant header priority according to tls.peet.ws api;
bogdanfinn Aug 25, 2022
29d453b
updated dependencies;
bogdanfinn Aug 31, 2022
0020b5a
updated dependencies;
bogdanfinn Sep 11, 2022
2af9195
updated dependencies;
bogdanfinn Sep 14, 2022
1d11b26
updated dependencies;
bogdanfinn Sep 27, 2022
6979eee
access http2 transports configuration;
bogdanfinn Oct 4, 2022
5ba4d28
updated dependencies;
bogdanfinn Oct 5, 2022
a188ddf
updated dependencies;
bogdanfinn Oct 5, 2022
1bca051
updated dependencies;
bogdanfinn Oct 19, 2022
699053b
updated dependencies;
bogdanfinn Nov 6, 2022
2316591
updated dependencies;
bogdanfinn Nov 11, 2022
62b2394
updated dependencies;
bogdanfinn Nov 20, 2022
d9da750
updated dependencies;
bogdanfinn Dec 6, 2022
9f77cf3
removed log;
bogdanfinn Dec 6, 2022
a28a654
make header priority customizeable via transport;
bogdanfinn Dec 17, 2022
9ae62e8
updated dependencies;
bogdanfinn Dec 17, 2022
e31480a
fixed streamId in combination with priority header frames;
bogdanfinn Dec 21, 2022
ef094bb
updated dependencies;
bogdanfinn Jan 16, 2023
46af5ec
made decompression of body public;
bogdanfinn Jan 30, 2023
a8bab38
updated dependencies;
bogdanfinn Feb 18, 2023
5f73d7e
updated dependencies;
bogdanfinn Feb 24, 2023
006a1d3
updated dependencies;
bogdanfinn Mar 11, 2023
959a7f7
updated dependencies;
bogdanfinn Apr 8, 2023
f58254f
Allow IdleConnTimeout configuration
jsnjack Apr 17, 2023
4212444
Merge pull request #1 from jsnjack/h2_idleconntimeout
bogdanfinn Apr 21, 2023
6f9542d
do not decompress body in http2 when compression is disabled;
bogdanfinn Apr 21, 2023
65e9c42
check correct field for disabled decompression;
bogdanfinn Apr 27, 2023
cbd4030
allow doublequotes in cookie values;
bogdanfinn Jun 1, 2023
180cb3a
removed error and log when client receives another frame than setting…
bogdanfinn Aug 27, 2023
b5ab242
do not error on redirect without location header;
bogdanfinn Nov 26, 2023
6005930
cookiejar return more fields;
bogdanfinn Nov 29, 2023
21cc550
Update push_consume.go
batuzyn Dec 13, 2023
46d2855
updated utls version;
bogdanfinn Sep 12, 2023
a77d8c5
Merge pull request #4 from bogdanfinn/new-utls-version-2
bogdanfinn Dec 15, 2023
c5bb5a2
Merge pull request #3 from batuzyn/patch-1
bogdanfinn Dec 15, 2023
e92d7b4
updated utls;
bogdanfinn Dec 15, 2023
f4f7759
fix
bogdanfinn Dec 15, 2023
1ec8f13
do not strip leading and trailing cookie doublequotes if allowed
roachadam Feb 18, 2024
81a31e4
added new function to add header values with automatically append the…
bogdanfinn Apr 10, 2024
a91d9b2
feat(http2): added NO_RFC7540_PRIORITIES
snekROmonoro Nov 12, 2024
3ef18c2
chore: updated dependencies
snekROmonoro Nov 12, 2024
320fe4c
Add support for zstd compression
shrimpwtf Jun 11, 2024
26676c5
resolved the code review comments from the previous changeset;
bogdanfinn Nov 17, 2024
ebd58ca
updated dependencies;
bogdanfinn Nov 17, 2024
3e2da78
add secure and httpOnly to return in cookie;
bogdanfinn Dec 3, 2024
03441ac
updated dependencies;
bogdanfinn Dec 8, 2024
f377d7e
add nil check on pipe buffer
TheFiordi Jan 29, 2025
bf0cf07
updated dependencies;
bogdanfinn Feb 6, 2025
8009627
updated dependencies;
bogdanfinn Feb 7, 2025
a535bcd
add SETTINGS_ENABLE_CONNECT_PROTOCOL support
swftq Feb 15, 2025
046c8ff
Update request.go
PandaWorker Oct 13, 2024
cb004bc
Update go.mod
PandaWorker Oct 13, 2024
ad66ba6
replace module name
Feb 12, 2025
40aa17f
feat: skip user-agent header
Feb 12, 2025
5c154cd
Window update frame adjustments (#10)
bogdanfinn Feb 26, 2025
35eaa3b
updated go mod file;
bogdanfinn Feb 26, 2025
b31ca90
fixed max header list size if not set on client profile;
bogdanfinn Feb 26, 2025
a7d3ebd
Revert "fixed max header list size if not set on client profile;"
bogdanfinn Mar 1, 2025
373fcbc
Revert "Window update frame adjustments (#10)"
bogdanfinn Mar 1, 2025
474636f
updated go version and dependencies;
bogdanfinn Jun 17, 2025
98dea82
added responsecontroller from net/http;
bogdanfinn Aug 30, 2025
65e61c7
updated dependencies;
bogdanfinn Sep 11, 2025
0d1f497
>ref: sanitizeCookieValue,parseCookieValue
nv1412512 Oct 15, 2025
67c1acf
fix inter errors
nv1412512 Oct 15, 2025
4a2dfcc
>ref: remove , as browsers dont quote on ,
nv1412512 Oct 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.txt
*.txt
.idea
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.24.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- This note is not necessary on this repo, but I won't delete it as it should be included on the original one.
**NOTE**
This maintenance of this library has moved over to [Carcraftz](https://github.com/Carcraftz/fhttp). The only use for this repository is so imports will not break.
This maintenance of this library has moved over to [Carcraftz](https://github.com/bogdanfinn/fhttp). The only use for this repository is so imports will not break.

The "f" stands for "fly" *(or "flex")*. fhttp is a fork of `net/http` that provides an array of features pertaining to the fingerprint of the golang `http` client. Through these changes, the `http` client becomes much more flexible, and when combined with transports such as [uTLS](https://github.com/refraction-networking/utls) it can mitigate fingerprinting requests, reducing the chances that a server detects they were made by a golang program, instead having them appear to originate from a regular Chrome browser.

Expand Down Expand Up @@ -104,7 +104,7 @@ with

```go
import (
http "github.com/Carcraftz/fhttp"
http "github.com/bogdanfinn/fhttp"
)
```

Expand Down
7 changes: 4 additions & 3 deletions alpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ package http_test
import (
"bufio"
"bytes"
tls "github.com/Carcraftz/utls"
"crypto/x509"
"fmt"
"io"
"strings"
"testing"

. "github.com/Carcraftz/fhttp"
"github.com/Carcraftz/fhttp/httptest"
tls "github.com/bogdanfinn/utls"

. "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/httptest"
)

func TestNextProtoUpgrade(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions cgi/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package cgi

import (
"bufio"
tls "github.com/Carcraftz/utls"
"errors"
"fmt"
"io"
Expand All @@ -19,7 +18,9 @@ import (
"strconv"
"strings"

http "github.com/Carcraftz/fhttp"
tls "github.com/bogdanfinn/utls"

http "github.com/bogdanfinn/fhttp"
)

// Request returns the HTTP request as represented in the current
Expand Down
2 changes: 1 addition & 1 deletion cgi/child_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"testing"

http "github.com/Carcraftz/fhttp"
http "github.com/bogdanfinn/fhttp"
)

func TestRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cgi/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"strconv"
"strings"

http "github.com/Carcraftz/fhttp"
http "github.com/bogdanfinn/fhttp"

"golang.org/x/net/http/httpguts"
)
Expand Down
4 changes: 2 additions & 2 deletions cgi/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"testing"
"time"

http "github.com/Carcraftz/fhttp"
"github.com/Carcraftz/fhttp/httptest"
http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/httptest"
)

func newRequest(httpreq string) *http.Request {
Expand Down
6 changes: 3 additions & 3 deletions cgi/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"testing"
"time"

http "github.com/Carcraftz/fhttp"
"github.com/Carcraftz/fhttp/httptest"
"github.com/Carcraftz/fhttp/internal/testenv"
http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/httptest"
"github.com/bogdanfinn/fhttp/internal/testenv"
)

// This test is a CGI host (testing host.go) that runs its own binary
Expand Down
71 changes: 32 additions & 39 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package http

import (
"context"
tls "github.com/Carcraftz/utls"
"encoding/base64"
"errors"
"fmt"
Expand All @@ -23,6 +22,8 @@ import (
"strings"
"sync"
"time"

tls "github.com/bogdanfinn/utls"
)

// A Client is an HTTP client. Its zero value (DefaultClient) is a
Expand Down Expand Up @@ -53,7 +54,6 @@ import (
// with the expectation that the Jar will insert those mutated cookies
// with the updated Values (assuming the origin matches).
// If Jar is nil, the initial cookies are forwarded without change.
//
type Client struct {
// Transport specifies the mechanism by which individual
// HTTP requests are made.
Expand Down Expand Up @@ -423,11 +423,11 @@ func basicAuth(username, password string) string {
// the following redirect codes, Get follows the redirect, up to a
// maximum of 10 redirects:
//
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
//
// An error is returned if there were too many redirects or if there
// was an HTTP protocol error. A non-2xx response doesn't cause an
Expand All @@ -450,11 +450,11 @@ func Get(url string) (resp *Response, err error) {
// following redirect codes, Get follows the redirect after calling the
// Client's CheckRedirect function:
//
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
//
// An error is returned if the Client's CheckRedirect function fails
// or if there was an HTTP protocol error. A non-2xx response doesn't
Expand Down Expand Up @@ -513,17 +513,6 @@ func redirectBehavior(reqMethod string, resp *Response, ireq *Request) (redirect
shouldRedirect = true
includeBody = true

// Treat 307 and 308 specially, since they're new in
// Go 1.8, and they also require re-sending the request body.
if resp.Header.Get("Location") == "" {
// 308s have been observed in the wild being served
// without Location headers. Since Go 1.7 and earlier
// didn't follow these codes, just stop here instead
// of returning an error.
// See Issue 17773.
shouldRedirect = false
break
}
if ireq.GetBody == nil && ireq.outgoingLength() != 0 {
// We had a request body, and 307/308 require
// re-sending it, but GetBody is not defined. So just
Expand Down Expand Up @@ -633,8 +622,10 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
if len(reqs) > 0 {
loc := resp.Header.Get("Location")
if loc == "" {
resp.closeBody()
return nil, uerr(fmt.Errorf("%d response missing Location header", resp.StatusCode))
// While most 3xx responses include a Location, it is not
// required and 3xx responses without a Location have been
// observed in the wild. See issues #17773 and #49281.
return resp, nil
}
u, err := req.URL.Parse(loc)
if err != nil {
Expand Down Expand Up @@ -678,7 +669,9 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
// Add the Referer header from the most recent
// request URL to the new one, if it's not https->http:
if ref := refererForURL(reqs[len(reqs)-1].URL, req.URL); ref != "" {
req.Header.Set("Referer", ref)
if !req.Header.has("Referer") && !req.Header.has("referer") {
req.Header.Set("Referer", ref)
}
}
err = c.checkRedirect(req, reqs)

Expand Down Expand Up @@ -881,11 +874,11 @@ func (c *Client) PostForm(url string, data url.Values) (resp *Response, err erro
// the following redirect codes, Head follows the redirect, up to a
// maximum of 10 redirects:
//
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
//
// Head is a wrapper around DefaultClient.Head
func Head(url string) (resp *Response, err error) {
Expand All @@ -896,11 +889,11 @@ func Head(url string) (resp *Response, err error) {
// following redirect codes, Head follows the redirect after calling the
// Client's CheckRedirect function:
//
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
// 301 (Moved Permanently)
// 302 (Found)
// 303 (See Other)
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
func (c *Client) Head(url string) (resp *Response, err error) {
req, err := NewRequest("HEAD", url, nil)
if err != nil {
Expand All @@ -926,9 +919,9 @@ func (c *Client) CloseIdleConnections() {
}

// cancelTimerBody is an io.ReadCloser that wraps rc with two features:
// 1) on Read error or close, the stop func is called.
// 2) On Read failure, if reqDidTimeout is true, the error is wrapped and
// marked as net.Error that hit its timeout.
// 1. on Read error or close, the stop func is called.
// 2. On Read failure, if reqDidTimeout is true, the error is wrapped and
// marked as net.Error that hit its timeout.
type cancelTimerBody struct {
stop func() // stops the time.Timer waiting to cancel the request
rc io.ReadCloser
Expand Down
33 changes: 5 additions & 28 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package http_test
import (
"bytes"
"context"
tls "github.com/Carcraftz/utls"
"encoding/base64"
"errors"
"fmt"
Expand All @@ -25,9 +24,11 @@ import (
"testing"
"time"

. "github.com/Carcraftz/fhttp"
"github.com/Carcraftz/fhttp/cookiejar"
"github.com/Carcraftz/fhttp/httptest"
tls "github.com/bogdanfinn/utls"

. "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/cookiejar"
"github.com/bogdanfinn/fhttp/httptest"
)

var robotsTxtHandler = HandlerFunc(func(w ResponseWriter, r *Request) {
Expand Down Expand Up @@ -531,30 +532,6 @@ func TestClientRedirectUseResponse(t *testing.T) {
}
}

// Issue 17773: don't follow a 308 (or 307) if the response doesn't
// have a Location header.
func TestClientRedirect308NoLocation(t *testing.T) {
setParallel(t)
defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
w.Header().Set("Foo", "Bar")
w.WriteHeader(308)
}))
defer ts.Close()
c := ts.Client()
res, err := c.Get(ts.URL)
if err != nil {
t.Fatal(err)
}
res.Body.Close()
if res.StatusCode != 308 {
t.Errorf("status = %d; want %d", res.StatusCode, 308)
}
if got := res.Header.Get("Foo"); got != "Bar" {
t.Errorf("Foo header = %q; want Bar", got)
}
}

// Don't follow a 307/308 if we can't resent the request body.
func TestClientRedirect308NoGetBody(t *testing.T) {
setParallel(t)
Expand Down
9 changes: 5 additions & 4 deletions clientserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"compress/gzip"
"crypto/rand"
"crypto/sha1"
tls "github.com/Carcraftz/utls"
"fmt"
"hash"
"io"
Expand All @@ -28,9 +27,11 @@ import (
"testing"
"time"

. "github.com/Carcraftz/fhttp"
"github.com/Carcraftz/fhttp/httptest"
"github.com/Carcraftz/fhttp/httputil"
tls "github.com/bogdanfinn/utls"

. "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/httptest"
"github.com/bogdanfinn/fhttp/httputil"
)

type clientServerTest struct {
Expand Down
Loading