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
1
vote
1 answer

Remove trailing slash from urls - Go static server

I've set up a simple Go static file server with http.FileServer. If I have a directory structure like public > about > index.html, the server will correctly resolve /about to about > index.html, but it adds a trailing slash so the url becomes…
Luke Johnson
  • 183
  • 2
  • 12
1
vote
0 answers

Use custom IP for a Domain without using built in DNS Resolver (while using Proxy) in Go

I am developing an application that has to connect through a HTTP Proxy and then use that Connection to do a GET Request to a domain name. The Domain Name should be resolved manually e.g. giving it the IP it should dial. Exactly thats the issue im…
1
vote
2 answers

http host and port information in HandleFunc

I am try to start multiple http servers listening on different ports in same package. In my test HandleFunc function I need to print our host and the port of information of the http server which served the request. How would I do that? Here is my…
Dinesh Gowda
  • 1,044
  • 3
  • 13
  • 29
1
vote
1 answer

field state of web.Request struct not cloning properly in Golang

In trying to set up two different web.Request states for use in some test cases, one without any headers and one with, I run into issue: Setup I create fakeRequest,fakeRequestNoHeaders thus: // create fake request fakeRequest :=…
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
0
votes
2 answers

http client: faster timeout when no network

When making a http Get request in Go, it waits the full timeout time before returning an error, even when there is no network connection. I assume in the internals it knows pretty quickly it has failed; I'd like that error to propagate up as soon as…
scosman
  • 2,343
  • 18
  • 34
0
votes
1 answer

Get stacktrace when context.Context is canceled by http.TimeoutHandler

For debugging purposes, how can I get more information on exactly where my http.TimeoutHandler wrapped handler canceled an active http.Request::Context()? Ideally, a stacktrace should be logged. Background: The server is set up like this: mux…
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
0
votes
0 answers

Go HTTP Transport.Proxy Connection Reuse

I'm trying to get a better idea of how Go's HTTP Transport "Proxy" field works. It's a func(*Request) (*url.URL, error) with the following description: Proxy specifies a function to return a proxy for a given Request. This suggests that it's…
Jordan
  • 3,998
  • 9
  • 45
  • 81
0
votes
0 answers

How do I pass cookies from HEAD to POST-Request

I need to pass csrf cookies _gorila_csrf and csrf_token from my HEAD-Request to my POST-Request. What is the best practice for that? For now I get the Cookie Value with res.Cookies() for the two cookies, built the Cookie-Header Value and pass to the…
sokolata
  • 491
  • 3
  • 7
  • 21
0
votes
1 answer

Reusing vs Creating new instance of http.Transport in httputil.ReverseProxy

I've implemented http reverse proxy middleware which used with Gin framework app: app := gin.New() app.Use(proxy.ReverseProxy("127.0.0.1:8008")) // HERE I'm attaching ReverseProxy middleware In ReverseProxy method I'm creating instance of…
num8er
  • 18,604
  • 3
  • 43
  • 57
0
votes
1 answer

Should I reuse context object in http server when calling other service?

I am developing a server application with the net/http package. Everytime a request arrives, the net/http package reads the request and create a http.Request object. My server needs to call AWS DynamoDB to serve every request, when calling…
codewarrior
  • 723
  • 7
  • 22
0
votes
0 answers

GO get original router url of a request

In flask, I do from flask import request route = request.url_rule.rule if request.url_rule else request.path So that I can get the "original" URL registered in Blueprint. For example, when API http://localhost/v1/user/001 was called, I'd got…
romlym
  • 561
  • 1
  • 7
  • 26
0
votes
1 answer

Golang minio client can put and remove but not stat or get objects

My go application can upload and remove objects from a Minio server on the same docker network but statObject and getObject return empty information. The file does exist in the minio console. Here is my code. func downloadFromMinio(rs *appResource,…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
0
votes
1 answer

golang http disable TRACE method

Is there something like the traceEnable parameter in apache, in golang net/http? I do have something like the following, but I do want to listen to GET, POST and HEAD, however not to the TRACE method go func() { logger.Log( …
Hons
  • 3,804
  • 3
  • 32
  • 50
0
votes
3 answers

golang - Exit http handler from anywhere

I'm using the net/http package and wondering how I can exit the handler from anywhere in the code. Say I have this code: func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) } func handler(w http.ResponseWriter, r…
Jon Flynn
  • 440
  • 6
  • 15
0
votes
1 answer

How to design RestAPI for too many tables in Golang

I think if i keep using the method below, i'll have to write too much code. I declared structures for all the tables. and i used the go validate package for validation. [types.go] type TableA struct { Field1 string `json:"field1"…
clean314
  • 71
  • 4
1 2 3
8 9