Giter Club home page Giter Club logo

kiota-http-go's Introduction

Kiota Http Library for Go

Go

The Kiota HTTP Library for Go is the Go HTTP library implementation with net/http.

A Kiota generated project will need a reference to a HTTP package to make HTTP requests to an API endpoint.

Read more about Kiota here.

Using the Kiota Http Library for Go

go get github.com/microsoft/kiota-http-go
httpAdapter, err := kiotahttp.NewNetHttpRequestAdapter(authProvider)

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

kiota-http-go's People

Contributors

andrueastman avatar ashmrtn avatar baywet avatar dependabot[bot] avatar fey101 avatar github-actions[bot] avatar meain avatar melgendyjc avatar microsoft-github-operations[bot] avatar microsoftopensource avatar nerdjeremia avatar rkodev avatar steveruckdashel avatar xdpcs avatar zhangyangjing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiota-http-go's Issues

Allow users to handle the raw response object without stopping processing of parseable

When a user specifies a ResponseHandler to intercept processing of the response object in any of the Send commands, the user must provide the logic to return a Parseable and handle all the error processing, edge cases in serialization e.t.c

We should allow users to have access to the response object while allowing the net_request_adapter to process the request to completion as its possible to have users who only want to access parts of the response e.g response headers.

The proposal seeks to solve

  1. Allow a ResponseHandler to return a nil value without causing a casting error
  2. Allow users to define a response handler that is not final, i.e users can define a handler that will allow access to the raw http.Response while still delegating the responsibility to return a parse able object from the adapter

Setting infinite context timeout

This issue is a follow-up for #70 . Thanks for the quick solution for the original issue. What is the opinion on not setting a context timeout if the http timeout is 0?

Since the library sets the timeout to 100, I think we can assume that if we get a value of 0 for http timeout, it is because the user explicitly overrode the value to 0. As of now, if the user sets the timeout to 0 assuming it to get infinite timeout (for example to download large files) it will fail for all requests as it will end up setting a context deadline 0s into the future.

Do let me know if there is some specific reasoning behind the original 100s timeout that I am missing. I was not able to find the reason for the original change in the linked issue.

/cc @rkodev

Add support to provide default middleware options in kiota factory

Hi everyone! ๐Ÿ‘‹
I started building a new SDK in Go for Apicurio Registry, my experience performing a GET has been completely smooth, great job!

It required quite some digging to find out that an interceptor for compression is enabled by default, and that's surprising, I haven't found a better way to disable it than creating a new client without it:

	adapter, err := kiotaHttp.NewNetHttpRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(
		&authProvider,
		nil,
		nil,
		kiotaHttp.GetDefaultClient(
			kiotaHttp.NewRetryHandler(),
			kiotaHttp.NewRedirectHandler(),
			kiotaHttp.NewParametersNameDecodingHandler(),
			// NewCompressionHandler(),
			kiotaHttp.NewUserAgentHandler(),
			kiotaHttp.NewHeadersInspectionHandler(),
		),
	)

My expectation would be: compression should be disabled by default and we should document how to toggle it on and off

unchecked type conversion results in panic

Hello all,

I ran into an issue where overriding the default transport in net/http (net/http.DefaultTransport) results in the follow panic:

interface conversion: http.RoundTripper is *otelhttp.Transport, not *http.Transport

I traced the issue back to

defaultTransport := nethttp.DefaultTransport.(*nethttp.Transport).Clone()

By casting to the concrete type *nethttp.Transport, you preclude the use of other valid implementations of http.RoundTripper. By not checking the conversion, this line results in a panic.

Is there some way to globally override default 100s timeout

From microsoftgraph/msgraph-sdk-go#302 (comment) and #24 , looks like the library by default adds a 100s timeout if none is present. I understand that we can pass a context with a Deadline, but this becomes a problem when we have to do this for all requests. I was hoping to use the Timeout in http client instead of a context deadline. Is there some way to globally override this 100s timeout?

Other references:

map XXX error status code

related to microsoft/kiota#4025
add a 3rd case in the error handling of the request adapter for XXX (must be the 3rd in the order, first sepcific code, then 4XX or 5XX depending on the first number, then XXX)

No HTTP status code information returned if response body is empty

My team and I have discovered some resources that take too long to return data for certain page sizes. These resources consistently result in 503 errors with no body content being sent back. The retries in the default graph client don't get us passed the 503s either. When using the kiota-serialization-json-go library and other graph SDK libraries to communicate with the Graph servers we only get an error of "content is empty" back from graph SDK in these situations

This is problematic because we lose information about the HTTP status code. For example, we've found that if we see consistent 503s with no content returned we can reduce the requested page size to make progress. This strategy would probably not make sense if the status code was a 4xx error though

Would it be possible to update the graph SDK (I'm unsure which repo the update would be in) to somehow return the HTTP status code? We've worked around the issue for the moment by adding our own middleware to the graph client and explicitly checking for no content and returning an error, but that feels a bit heavy handed

As an additional note, depending on which graph SDK repo the fix is made in, other repos may need updating as well. For example, all the serialization libraries contain the line errors.New("content is empty") like I linked above

Response Handler Set Up in Request Context is never Retrieved

Current implementation of the Response Handler requires the instance to be passed via the context object.
However the function context.WithValue returns a pointer to a different instance on the object instead of the original pointer.

A fix is required to return the actual pointer value

Redirect handler fails when getting drive items using Graph sdk

See microsoftgraph/msgraph-sdk-go#485

I'm trying to get the contents of a drive item. When I use the SDK client to make the call, I get a 400. However, when I curl the same URL, it works.

Details

Here's roughly what happens:

  1. Client calls https://graph.microsoft.com/v1.0/drives/<drive-id>/items/<item-id>/content.
    graphClient.DrivesById(driveId).ItemsById(itemId).Content().Get(ctx, nil)
  2. API returns 302 to https://mytech.sharepoint.com/_layouts/15/download.aspx?UniqueId=ugly-gu-id&Translate=false&tempauth=some.jwt.token&ApiVersion=2.0
  3. After client redirects, the API returns 400 with the message

    <h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>0123

However, If I curl the redirect URL, e.g.

curl "https://mytech.sharepoint.com/_layouts/15/download.aspx?UniqueId=ugly-gu-id&Translate=false&tempauth=some.jwt.token&ApiVersion=2.0" > my.docx

the API returns a valid file.

Someone in the original thread suggested that the problem is here:

The fix should probably go here:

result := request.Clone(request.Context())

The URL's host is checked in order to drop the Authorization header if it's different, but the Host: header is never updated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.