0
votes

I have an API i need to pull information out of the header and make another call. I've tried a number of approaches, but can't seem to fetch the headers only. There is no other response.

I've tried having it return various Response objects, such as okhttp3 headers, Retrofit headers, HttpHeaders, etc, but getting a EOF at first char.

api:

@POST("api/booking/search")
fun bookFlight(@Body bookFlightDetails: BookFlightDetails): Observable<Response<Headers>>

manager class:

class DataManager(context: AllegiantApplication, private val mApi: RxRestServices) {

fun bookFlight(bookingDetails: BookFlightDetails) : Observable<Response<Headers>>? {
    return mApi.bookFlight(bookingDetails)
}

And fetching it with my repo:

 fun bookFlight(bookingDetails: BookFlightDetails) {
    mDataManager.bookFlight(bookingDetails)
            ?.subscribeOn(Schedulers.io())
            ?.observeOn(AndroidSchedulers.mainThread())
            ?.subscribe({
                processHeader(it)
            }, {
                error ->  Log.d("TAG",  error.localizedMessage)  // <- EOF at 1st char
            }
            )
}

Can anyone tell me how I need to structure my api calls to get just the header?

1
could you show us processHeader pls? - Fred

1 Answers

0
votes

second time this month I've answered my own question.

This one was two-fold. 1) getting the right response type. I went with

Observable<Response<ResponseBody>>

and that allowed me to see the header. However, the second piece was that I was consuming it before getting it to processHeader.I was giving processHeader it which consumed the response. I changed the subscribe method to from:

  processHeader(it)

to:

  val headers = it?.headers()
  processHeader(headers)

so processHeaders sees only the header the response can be "consumed" normally