Git Product home page Git Product logo

Comments (14)

echochamber avatar echochamber commented on August 21, 2024 4

I think serialized name is still a bit foreign. I'd prefer calling it something like http_header_name.

header! {
    rust_name = Foo;
    http_header_name = "X-Foo";
    repr = [String];
}

from reqwest.

seanmonstar avatar seanmonstar commented on August 21, 2024 2

Could you switch to the http create for headers?

The upcoming 0.9 release upgrades to hyper 0.12, which adds support for the http crate. I'm working an upgrade for the typed headers as well, so each can pick how to deal with headers.

from reqwest.

seanmonstar avatar seanmonstar commented on August 21, 2024 1

It still would be nice, that reqwest reexported header! macro, as it is the only thing, why I directly have to depend on hyper.

I know! But macro_reexport is an unstable feature, so it cannot be done on stable Rust. 😢

from reqwest.

seanmonstar avatar seanmonstar commented on August 21, 2024 1

That's a possibility. I wonder if it makes sense to copy verbatim, of if this is an opportunity to make the macro less confusing. Perhaps keywords in the macro instead of sigils would make things more clear?

header! {
    name = "X-Foo";
    type = Foo;
    repr = [String]; // I don't know if Vec<String> would work, but if it would, maybe that's better?
}

from reqwest.

aleksanb avatar aleksanb commented on August 21, 2024 1

I like the key-value style of your suggestion,
although the choice of key "type" for the generated rust struct feels weird,
as it's not a preexisting type but something generated by the macro.

Alternatives quickly get verbose, f.ex with

header! {
    rust_name = Foo;
    serialized_name = "X-Foo";
    repr = [String];
}

from reqwest.

seanmonstar avatar seanmonstar commented on August 21, 2024 1

@softprops assuming you're asking about current reqwest (0.8.x), you can make use of type inference, or use turbofish syntax:

let ty: ContentType = res.headers().get().unwrap();

let len = res.headers().get::<ContentLength>().unwrap;

from reqwest.

aleksanb avatar aleksanb commented on August 21, 2024

I went for raw_headers as opposed to the typed headers in an app which uses reqwest for now,
couldn't figure out how to merge the output of the header! macro from hyper with reqwest.

I'd be up for implementing this if someone could guide me in the correct direction (Is a copy-paste of the header macro the best solution?).

from reqwest.

retrry avatar retrry commented on August 21, 2024

This is how I used header! macro with reqwest

header! { (CustomAuthenticationHeader, "custom_auth") => [String] }

let http_client = reqwest::Client::new().unwrap();
let mut response = http_client.post(url)
  .header(CustomAuthenticationHeader(api_key))
  .body(body)
  .send()
  .unwrap();

It still would be nice, that reqwest reexported header! macro, as it is the only thing, why I directly have to depend on hyper.

from reqwest.

aleksanb avatar aleksanb commented on August 21, 2024

Could we as a stopgap measure til the feature becomes stable, re-implement the macro in the reqwest library?

from reqwest.

softprops avatar softprops commented on August 21, 2024

are there any examples for how to get a header? reqwest's header map takes a value argument and hypers takes a type argument.

from reqwest.

softprops avatar softprops commented on August 21, 2024

Sry I was mistaken. I was actually using the http crate which I thought reqwest used.

from reqwest.

kornelski avatar kornelski commented on August 21, 2024

Could you switch to the http create for headers? It has HeaderName::from_str.

The macros are enormous hassle. I also don't see how such type-strict solution could work with header names only known at run time (e.g. Vary and Connection can refer to arbitrary header names).

from reqwest.

otavio avatar otavio commented on August 21, 2024

@seanmonstar when doing it, are you also keeping support for the ByteRangeSpec and others?

I ended doing a hackish solution for now, when upgrading to 0.9 release, but it is far from neat... :-(

from reqwest.

seanmonstar avatar seanmonstar commented on August 21, 2024

reqwest no longer has typed headers built in (could conceivably come back some day).

from reqwest.

Related Issues (20)

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.