Questions tagged [go-http]

This tag is for questions related to Go's HTTP package

Go's net/http package provides HTTP client and server implementations.

121 questions
29
votes
2 answers

How do you use Go 1.16 embed features in subfolders/packages?

Go 1.16 is out and I want to use the new embed features. I can get it to work if everything is in the main package. But it's not clear how to handle accessing resources from subfolders/packages. Trying to do it with embed.FS support. e.g. I have a…
PrecisionPete
  • 3,139
  • 5
  • 33
  • 52
22
votes
2 answers

when to use hijack in golang?

I don't understand why we use hijack, since I can write something into response body directly, could anyone explain this? func writeSome(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "write some thing") } it is same as this: func…
crafet
  • 476
  • 2
  • 6
  • 14
17
votes
2 answers

Go http client timeout vs context timeout

What's the difference between timeout set in http.Client and timeout set in request's context? I've seen 2 ways of setting timeout in http client. First: ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() req, err…
Jake Muller
  • 925
  • 4
  • 18
  • 25
13
votes
1 answer

tls: no renegotiation error on HTTP request

I'm trying to make a simple HTTP request in Go, after directly following the guides I keep getting the same error: local error: tls: no renegotiation I don't quite understand how to interpret this? I know it's not an issue on the server as when I…
Adrian Coutsoftides
  • 1,203
  • 1
  • 16
  • 38
10
votes
2 answers

Add headers for each HTTP request using client

I know that I can add headers to each HTTP request manually using cli := &http.Client{} req, err := http.NewRequest("GET", "https://myhost", nil) req.Header.Add("X-Test", "true") if err != nil { panic(err) } rsp, err := cli.Do(req) but I want…
Kirill
  • 7,580
  • 6
  • 44
  • 95
10
votes
1 answer

Dial tcp I/O timeout on simultaneous requests

I am building a tool in Go that needs to make a very large number of simultaneous HTTP requests to many different servers. My initial prototype in Python had no problem doing a few hundred simultaneous requests. However, I have found that in Go this…
Neverbolt
  • 111
  • 1
  • 1
  • 5
8
votes
2 answers

dial tcp i/o timeout with HTTP GET request

Running into some error, I must be overlooking something. How can I debug this? Dropping connections? I read the following: golang - Why net.DialTimeout get timeout half of the time? Go. Get error i/o timeout in server program golang get massive…
R.J.
  • 161
  • 1
  • 1
  • 10
8
votes
1 answer

Go hijack client connection

Go language http connection hijacking. I know how to hijack on server side. http://golang.org/pkg/net/http/#example_Hijacker But is there way to hijack it on clients side?
Max
  • 6,286
  • 5
  • 44
  • 86
6
votes
1 answer

what is the benefit of using http hijacker

Go http pkg provide a Hijacker interface, can anyone tell when should I use it. I check the comment, after a Hijack call lets the caller take over the connection, the HTTP server library will not do anything else with the connection. I understand…
carter2000
  • 279
  • 1
  • 3
  • 9
5
votes
0 answers

Go equivalent of Python's requests.Session for making many requests with the same basic authentication?

Consider this example for making an HTTP request in Go with basic authentication: package main import ( "encoding/base64" "fmt" "io/ioutil" "net/http" "net/http/httptest" "strings" ) var userName = "myUserName" var password…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
5
votes
2 answers

How to determine if I've reached the size limit via Go's MaxBytesReader

I am new to Go, and using Mux to accept HTTP POST data. I would like to use the MaxBytesReader to ensure a client does not overwhelm my server. According to the code, there is a requestBodyLimit boolean which indicates whether that limit has been…
poundifdef
  • 18,726
  • 23
  • 95
  • 134
4
votes
1 answer

Difference between functioning of net.Listen and http.ListenAndServe

I'm new to Go and Networking. I know both net.Listen and http.ListenAndServe creates a server. But what is the difference between their functionality?
luffy
  • 105
  • 8
4
votes
2 answers

Golang - Hijack Arguments

When using Hijack() with a http.ResponseWriter instance Hijack() (net.Conn, *bufio.ReadWriter, error) What is the difference between reading from the net.Conn and the *bufio.ReadWriter?
Kim Byer
  • 283
  • 1
  • 4
  • 12
3
votes
1 answer

go-chi router override middleware to set content type

I have a go API which so far has always returned JSON. I use chi router and set it up using middleware like this in my main function: func router() http.Handler { r := chi.NewRouter() r.Use(render.SetContentType(render.ContentTypeJSON)) .... Now I…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
3
votes
2 answers

TLS : Handshake Failure Using GoLang tls client

I'm trying to connect to a server over SSL/TLS using golang http/tsl client which is resulting in 'Handshake Faliure(40)' error, but for some reason, this same endpoint works with CURL command. After some debugging, I have collected the following…
utkarsh sharma
  • 149
  • 2
  • 12
1
2 3
8 9